Date: Wed, 22 Nov 2023 14:16:00 +0200
In my opinion if exceptions were used more it would be worthy to add my
suggestion - your solution is too verbose.
On Wed, Nov 22, 2023 at 2:07 PM Lénárd Szolnoki via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Wed, 2023-11-22 at 13:56 +0200, sasho648 via Std-Proposals wrote:
> > Because I only care about the exception thrown at `func()` and don't
> > want to have exception handling for the rest of the code.
>
>
> int f() {
> const auto ptr = [&]() -> decltype(&func()) {
> try {
> return &func();
> } catch (...) {
> return nullptr;
> }
> }();
>
> // use ptr here, check for null, dereference, whatever
> }
>
> >
> > On Wed, Nov 22, 2023 at 1:54 PM Fabio Alemagna <falemagn_at_[hidden]>
> > wrote:
> > >
> > >
> > > Il mer 22 nov 2023, 12:50 sasho648 via Std-Proposals
> > > <std-proposals_at_[hidden]> ha scritto:
> > > > Ok use-case I was thinking is actually:
> > > >
> > > > int f() {
> > > >
> > > > try (auto &ref = func()) {
> > > > } catch(...) {
> > > > return -1;
> > > > }
> > > >
> > > > // use ref here
> > > > }
> > >
> > > Why would you want to use ref after the whole try-catch block?
> > >
> > > If func() does't throw, you can use ref right after its call,
> > > within the try block itself.
> > >
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
suggestion - your solution is too verbose.
On Wed, Nov 22, 2023 at 2:07 PM Lénárd Szolnoki via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Wed, 2023-11-22 at 13:56 +0200, sasho648 via Std-Proposals wrote:
> > Because I only care about the exception thrown at `func()` and don't
> > want to have exception handling for the rest of the code.
>
>
> int f() {
> const auto ptr = [&]() -> decltype(&func()) {
> try {
> return &func();
> } catch (...) {
> return nullptr;
> }
> }();
>
> // use ptr here, check for null, dereference, whatever
> }
>
> >
> > On Wed, Nov 22, 2023 at 1:54 PM Fabio Alemagna <falemagn_at_[hidden]>
> > wrote:
> > >
> > >
> > > Il mer 22 nov 2023, 12:50 sasho648 via Std-Proposals
> > > <std-proposals_at_[hidden]> ha scritto:
> > > > Ok use-case I was thinking is actually:
> > > >
> > > > int f() {
> > > >
> > > > try (auto &ref = func()) {
> > > > } catch(...) {
> > > > return -1;
> > > > }
> > > >
> > > > // use ref here
> > > > }
> > >
> > > Why would you want to use ref after the whole try-catch block?
> > >
> > > If func() does't throw, you can use ref right after its call,
> > > within the try block itself.
> > >
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2023-11-22 12:16:13