C++ Logo

std-proposals

Advanced search

Re: [std-proposals] throw = runtime_error;

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 13 Aug 2023 11:45:42 -0400
On Sun, Aug 13, 2023 at 10:24 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>
> What if we could set the type of what's thrown within a try block, as follows:
>
> try
> {
> throw = std::runtime_error;
>
> if ( something ) throw "bad happened";
>
> if ( something ) throw "worse happened;
>
> throw = std::logic_error;
>
> if ( something ) throw "even worse happened";
> }
>
> In the above snippet, the first two 'throw' statements throw an object of type 'runtime_error', and the third throws an object of type 'logic_error'.
>
> You could consider this feature to merely be a form of shorthand, but it could also be a versatile way of changing one line of code to affect much larger blocks of code.

... That's exactly what a form of "shorthand" is.

There is no motivation for this change. Nothing you state explains why
what you want would improve anything. You are just throwing out a
thing that occurred to you.

Received on 2023-08-13 15:45:54