Question on @nothrow

Vasileios Anagnostopoulos via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 2 00:35:29 PDT 2017


On Friday, 2 June 2017 at 07:33:05 UTC, Vasileios Anagnostopoulos 
wrote:
> On Thursday, 1 June 2017 at 17:03:52 UTC, Ali Çehreli wrote:
>> [...]
>
> But still I believe that @nothrow should be mandatory if there 
> is no possibility for a function to throw something. I 
> understand that in the DLL/LIB level this is not possible. 
> However, at least in the .di level it should be there.
>
> And if you want my two cents, after reading a lot I came to the 
> "personal" conclusion that Exception objects are wrong. For me 
> it is enough to have something like
>
> void A() {
>  raise;
> }
>
> void B() {
>  raise;
> }
>
> void C() {
>  raise;
> }
>
>
> void D () nothrow { //the compiler inferred from body that D 
> cannever throw
>
> scope(failure) {
>  writeln("The end of the world");
>  exit(1);
> }
>
> try {
>  A();
> } else try {
>   B();
> } else {
>  C();
> }
>
> }

Or simply

void A() {
  raise;
}

void B() nothrow {
}


void D () nothrow { //the compiler inferred from body that D 
cannever throw

try {
  A();
} else {
   B();
}

}


More information about the Digitalmars-d-learn mailing list