The try/except statement intercepts any exception raised by its protected statements.
The simplest form of try/except stops all exceptions, no matter their types:
try
statement-list
except
statement-list
end
If you want to access the exception object, you can use a exception trap like this:
try
statement-list
except on e: Exception do
statement-list
end
If you want to trap exceptions according to their types, you can use one or several exception traps:
try
statement-list
except on e: exception-type1 do
statement-list1
except on e: exception-type2 do
statement-list2
except on e: exception-type3 do
statement-list3
except
statement-list4
end
You can end a try/except statement with a finally clause:
try
statement-list
except on e: exception-type1 do
statement-list1
except on e: exception-type2 do
statement-list2
except on e: exception-type3 do
statement-list3
except
statement-list4
finally
statement-list5
end
This finally clause will always be executed, even if an exception is fired in any of the previous parts of the same statement. You can also use a finally clause without any previous except clauses.
The Freya Programming Language
Statements
raise statements
try/finally statements
try/fault statements
using statements
Expressions