Polyglot CheatSheet - Exception Handling

Updated: 2018-11-29

Java

  • try {}
  • catch {}
  • finally
  • throw

Python

Throw

raise ValueError('some error message')

Catch

try:
    code_that_may_raise_exception()
except ValueError as err:
    print(err.args)

C++

  • try {}
  • catch {}
  • No finally block
  • throw

Ruby

  • begin/end
  • rescue keyword
  • ensure
  • raise