handles this exception } catch (SecondExceptionClass $exception) { // Code that handles a different exception } finally { // Perform cleanup, whether an exception occurred or not. } PowerBuilder Exception handling is available in PowerBuilder versions 8.0 and above. TRY // Normal execution path CATCH (ExampleException ee) // deal with the ExampleException FINALLY // This optional section is executed upon termination of any of the try or catch blocks above END TRY PowerShell Version 1.0 trap [Exception] { # Statements that execute in the event of an exception } # Statements in which exceptions might be thrown Version 2.0 Try { Import-Module ActiveDirectory } Catch [Exception1] { # Statements that execute in the event of an exception, matching the exception } Catch [Exception2],[Exception3etc] { # Statements that execute in the event of an exception, matching any of the exceptions } Catch { # Statements that execute in the event of an exception, not handled more specifically } Python f = None try: f = open("aFileName", "w") f.write(could_make_error()) except IOError: print("Unable to open file") except: # catch all exceptions print("Unexpected error") else: # executed if no exceptions are raised print("File write completed successfully") finally: # clean-up actions, always executed if f: f.close() R tryCatch({ stop("Here an error is signaled") # default S3-class is simpleError a subclass of error cat("This and the following lines are not executed because the error is trapped before\n") stop( structure(simpleError("mySpecialError message"),class=c("specialError","error","condition")) ) } ,specialError=function(e){ cat("catches errors of class specialError\n") } ,error=function(e){ cat("catches the default error\n") } ,finally={ cat("do some cleanup (e.g., setwd)\n") } ) Rebol REBOL [ Title: "Exception and error handling examples" ] ; TRY a block; capturing an error! and converting to object! if error? exception: try [1 / 0][probe disarm exception] ; ATTEMPT results in the value of the block or the value none on error print attempt [divide 1 0] ; User generated exceptions can be any datatype! example: func ["A function to throw an exception" ][ throw "I'm a string! exception" ] catch [example] ; User generated exceptions can also be named, ; and functions can include additional run time attributes sophisticated: func ["A function to throw a named error exception" [catch] ][ throw/name make error! "I'm an error! exception" 'moniker ] catch/name [sophisticated] 'moniker Rexx signal on halt; do a = 1 say a do 100000 /* a delay */ end end halt: say "The program was stopped by the user"