exit Ruby begin # Do something nifty raise SomeError, "This is the error message!" # Uh-oh! rescue SomeError # This is executed when a SomeError exception # is raised rescue AnotherError => error # Here, the exception object is referenced from the # `error' variable rescue # This catches all exceptions derived from StandardError retry # This executes the begin section again else # This is executed only if no exceptions were raised ensure # This is always executed, exception or not end S-Lang try { % code that might throw an exception } catch SomeError: { % code that handles this exception } catch SomeOtherError: { % code that handles this exception } finally % optional block { % This code will always get executed } New exceptions may be created using the function, e.g., new_exception ("MyIOError", IOError, "My I/O Error"); will create an exception called as a subclass of . Exceptions may be generated using the throw statement, which can throw arbitrary S-Lang objects. Smalltalk [ "code that might throw an exception" ] on: ExceptionClass do: [:ex | "code that handles exception" ]. The general mechanism is provided by the message . Exceptions are just normal objects that subclass , you throw one by creating an instance and sending it a message, e.g., . The handling mechanism () is again just a normal message implemented by . The thrown exception is passed as a parameter to the handling block closure, and can be queried, as well as potentially sending to it, to allow execution flow to continue. Swift Exception handling is supported since Swift 2. enum MyException : ErrorType { case Foo(String, Int) } func someFunc() throws { throw MyException.Foo("not enough food", 2) } do { try someFunc() print("Not reached") } catch MyException.Foo(let s, let i) { print("MyException: \(s), \(i)") } catch { print("Unexpected exception : \(error)") } Tcl if { [ catch { foo } err ] } { puts "Error: $err" } Since Tcl 8.6, there is also a try command: try { someCommandWithExceptions } on ok {res opt} { # handle normal case. } trap ListPattern1 {err opt} { # handle exceptions with an errorcode matching ListPattern1 } trap ListPattern2 {err opt} { # ... } on error {err opt} { # handle everything else. } finally { # run whatever commands must run after the try-block. } VBScript With New Try: On Error Resume