Closed ire4ever1190 closed 1 year ago
Uses a bare raise statement inside the except blocks so that it reraises the exception instead of making a new one. Has the benefits of
raise
except
template reRaise() = when defined(bareRaise): raise else: raise newException(Exception, getCurrentExceptionMsg()) proc foo() = raise (ref ValueError)(msg: "Test") proc bar() = try: foo() except: reRaise() proc main() = try: bar() except ValueError: reRaise() main()
Bare raise
/tmp/test.nim(22) test /tmp/test.nim(17) main /tmp/test.nim(11) bar /tmp/test.nim(6) foo Error: unhandled exception: Test [ValueError]
New exception
/tmp/test.nim(22) test /tmp/test.nim(17) main /tmp/test.nim(13) bar Error: unhandled exception: Test [Exception]
See how the new exception loses the call to foo and also removes the ValueError type from the exception.
foo
ValueError
Sorry about the weird whitespace changes, my editor just does that
Uses a bare
raise
statement inside theexcept
blocks so that it reraises the exception instead of making a new one. Has the benefits ofBare raise
New exception
See how the new exception loses the call to
foo
and also removes theValueError
type from the exception.Sorry about the weird whitespace changes, my editor just does that