Exception handling

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 14 14:06:52 PDT 2017


On Friday, 14 July 2017 at 20:22:21 UTC, Ali Çehreli wrote:
> On 07/14/2017 12:36 PM, ANtlord wrote:
> > Hello! I've tried to use nothrow keyword and I couldn't get a
> state of
> > function satisfied the keyword. I have one more method that
> can throw an
> > exception; it is called inside nothrow method. Every type of
> an
> > exception from the throwable method is handled by the nothow
> method.
> >
> > ubyte throwable_fn(ubyte state) {
> >     if(state < 2) {
> >         return 1;
> >     } else if(state == 3) {
> >         throw new MyException1("qwe");
> >     } else {
> >         throw new MyException2("asd");
> >     }
> > }
>
> Although it's obvious to us that there are only those two 
> exceptions, the compiler cannot in general know that.

Not in general, no, but if the function's body (and the body of 
all functions it calls) are available, the compiler can aggregate 
the exception set and indeed perform a more precise nothrow 
analysis.


More information about the Digitalmars-d-learn mailing list