naitoh / py2rb

A code translator using AST from Python to Ruby.
MIT License
135 stars 17 forks source link

Bare except catching failure #10

Open jayvdb opened 3 years ago

jayvdb commented 3 years ago

The follow (bad) Python will catch the exception

try:
    raise Exception("foo")
except:
    print("Got it")

It is transpiled as

begin
  raise Exception, "foo"
rescue
  print("Got it")
end

That only catches the default Ruby exception StandardError. To catch the exception in Ruby, it needs to catch the top level Ruby exception class.

begin
  raise Exception, "foo"
rescue Exception
  print("Got it")
end