naitoh / py2rb

A code translator using AST from Python to Ruby.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bare except catching failure

jayvdb opened this issue · comments

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