Exceptions
This task is to give an example of an exception handling routine.
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
AppleScript
try set num to 1 / 0 --do something that might throw an error on error errMess number errNum --errMess and number errNum are optional display alert "Error # " & errNum & return & errMess end try
C++
C++ has no finally construct. Instead you can do this in the destructor of an object on the stack, which will be called if an exception is thrown.
try-catch
struct MyException { // data with info about exception }; void foo() { throw MyException(); } void call_foo() { try { foo(); } catch (MyException &exc) { // handle exceptions of type MyException and derived } catch (...) { // handle any type of exception not handled by above catches } }
Python
try-except-finally-else
Interpreter: Python 2.5
Before Python 2.5 it was not possible to use finally and except together.
try: foo() except TypeError: bar() finally: baz() else: # no exception occurred quux()