Exceptions/Catch an exception thrown in a nested call: Difference between revisions

Content added Content deleted
(add JavaScript)
m (Fixed lang tags.)
Line 61: Line 61:


c.f. [[Exceptions#ALGOL_68|ALGOL 68 Exceptions]] for more details.
c.f. [[Exceptions#ALGOL_68|ALGOL 68 Exceptions]] for more details.
<lang algol>MODE OBJ = STRUCT(
<lang algol68>MODE OBJ = STRUCT(
INT value,
INT value,
STRUCT(
STRUCT(
Line 169: Line 169:
typically with an error message.
typically with an error message.


<lang C++>
<lang cpp>#include <iostream>
#include <iostream>
class U0 {};
class U0 {};
class U1 {};
class U1 {};
Line 197: Line 196:
std::cout<< "Should never get here!\n";
std::cout<< "Should never get here!\n";
return 0;
return 0;
}</lang>
}
</lang>


Result:
Result:
Line 210: Line 208:
This example will first catch U0 and print "U0 Caught" to the console when it does. The uncaught U1 exception will then cause the program to terminate and print the type of the exception, location of the error, and the stack.
This example will first catch U0 and print "U0 Caught" to the console when it does. The uncaught U1 exception will then cause the program to terminate and print the type of the exception, location of the error, and the stack.


<lang csharp>using System; //Used for Exception and Console classes
<lang csharp>
using System; //Used for Exception and Console classes
class Exceptions
class Exceptions
{
{
Line 242: Line 239:
foo();
foo();
}
}
}</lang>
}
</lang>


Output:
Output:
Line 291: Line 287:
First exception will be caught and message will be displayed, second will be caught by default exception handler.
First exception will be caught and message will be displayed, second will be caught by default exception handler.


<lang D>
<lang D>module test;
module test;


import tango.io.Stdout;
import tango.io.Stdout;
Line 318: Line 313:
}
}


void main() { foo(); }
void main() { foo(); }</lang>
</lang>


Result:
Result: