Anonymous user
Exceptions: Difference between revisions
no edit summary
m (→{{header|C}}) |
No edit summary |
||
Line 57:
{
switch (setjmp(env)) {
case 0: /* try */
foo();
break;
case MY_EXCEPTION: /* catch MY_EXCEPTION */
/* handle exceptions of type MY_EXCEPTION */
break;
Line 73:
if an exception is thrown.
The exception can be of any type, this includes int's, other primitives, as well as objects.
===Defining exceptions===
struct MyException
{
// data with info about exception
};
===Throw exceptions===
// this function can throw any type of exception
void foo()
{
throw MyException();
}
// this function can only throw the types of exceptions that are listed
{
foo();▼
===Catching exceptions===
catch (MyException &exc)▼
// handle exceptions of type MyException and derived▼
catch (...)
}
Line 103 ⟶ 110:
'''Compiler''': MSVS 2005
===Defining exceptions===
public class MyException : Exception
{
// data with info about exception
};
===Throw exceptions===
void foo()
{
throw MyException();
}
===Catching exceptions===
{
▲ try {
▲ foo();
▲ catch (MyException e)
// handle any type of exception not handled by above catches
▲ {
▲ }
▲ {
▲ // handle any type of exception not handled by above catches
▲ }
▲ }
=={{header|Factor}}==
===Throw Exceptions===
Line 176 ⟶ 184:
=={{header|Java}}==
An exception needs to extend the Exception type.
===Defining exceptions===
//Checked exception
|