Exceptions: Difference between revisions

Content added Content deleted
Line 973: Line 973:


'''Defining exceptions'''
'''Defining exceptions'''
<lang elena>class MyException :: Exception
<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 new; raise.
MyException.new().raise()
}
]
</lang>
</lang>


'''Catching exceptions'''
'''Catching exceptions'''
<lang elena>try(o foo)
<lang elena>try
{
{
on(MyException e)
o.foo()
}
[
catch(MyException e)
// handle exceptions of type MyException and derived
{
]
// handle exceptions of type MyException and derived
}</lang>
}</lang>


'''Catching any exception'''
'''Catching any exception'''
<lang elena>o foo | if(:e)
<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>
};</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==