Exceptions: Difference between revisions
Content added Content deleted
Line 973: | Line 973: | ||
'''Defining exceptions''' |
'''Defining exceptions''' |
||
<lang elena>class MyException |
<lang elena>class MyException : Exception |
||
{ |
{ |
||
constructor new |
constructor new() |
||
<= new:"MyException raised" |
<= new:"MyException raised"; |
||
}</lang> |
}</lang> |
||
'''Throw exceptions''' |
'''Throw exceptions''' |
||
<lang elena>foo |
<lang elena>foo() |
||
{ |
|||
[ |
|||
MyException |
MyException.new().raise() |
||
} |
|||
] |
|||
</lang> |
</lang> |
||
'''Catching exceptions''' |
'''Catching exceptions''' |
||
<lang elena>try |
<lang elena>try |
||
{ |
{ |
||
o.foo() |
|||
} |
|||
[ |
|||
catch(MyException e) |
|||
⚫ | |||
{ |
|||
] |
|||
⚫ | |||
}</lang> |
}</lang> |
||
'''Catching any exception''' |
'''Catching any exception''' |
||
<lang elena>o |
<lang elena>o.foo() | if:(e) |
||
{ |
|||
[ |
|||
// handle any type of exception not handled by above catches |
// handle any type of exception not handled by above catches |
||
};</lang> |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |