Details
Description
A try block with no following except: or ensure: blocks produces an internal compiler error or runtime crash. Sample code:
try:
print "Foo"
On the .NET 1.1 runtime the low-level ILGenerator throws an exception which is caught and returned as an ICE:
ERROR: Internal compiler error: Incorrect code generation for exception block.
On Mono an assertion failure simply crashes the runtime:
-
- ERROR **: file reflection.c: line 835 (method_encode_clauses): assertion failed: (ex_info->handlers)
aborting...
- ERROR **: file reflection.c: line 835 (method_encode_clauses): assertion failed: (ex_info->handlers)
The case should probably be caught as illegal at a higher level and a descriptive error message returned; or if it's meant to be possible to do this, an empty catch block needs to be implicitly added in the emitted IL.
I've posted a short C# program which triggers the same emitter error on my bug report for the assertion failure on Mono:
http://bugzilla.ximian.com/show_bug.cgi?id=76002
If we have a try block with no except, should it be a syntax error, or should it add an except handler that re-raises, or an except that passes?
except e:
raise
or
except e:
pass //nothing happens if exception occurs
I'm guessing maybe the raise one is best, although technically "pass" means an empty block.