Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the type of the exception variable to 'object' #139

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

kpreisser
Copy link
Collaborator

Hi,
this PR addresses the two notes described in #90.

By changing the type of the exception variable in the catch clause from Exception to object, it is ensured that the finally block is also correctly skipped if objects are thrown that do not derive from Exception (which is possible in the CLR).

Note: When a non-Exception object is thrown and the control flow enters code generated by the C# compiler, the thrown object is wrapped in a RuntimeWrappedException so it can be caught by an catch (Exception) C# statement.
However, even with this I think it is safer to catch object in the generated IL code, to ensure JS finally blocks are not executed in such a case.

Additionally, the skipFinallyBlock variable is changed to a temporary variable.

Thanks!

…ct', and use a temporary variable for "skipFinallyBlock".

This ensures the finally block is also correctly skipped if objects are thrown that do not derive from Exception (which is possible in the CLR).
@paulbartrum
Copy link
Owner

I presume it's difficult to unit test this, since you can't actually throw a non-exception-derived object in c#? Seems good to me.

@paulbartrum paulbartrum merged commit e8ade10 into paulbartrum:master Jan 8, 2019
@kpreisser
Copy link
Collaborator Author

Thanks! Yes, its probably difficult to test this with C#. It would be possible to test it when the MethodGenerator that generates the try-catch also generates a throw statement in the same method (within the try block) that throws a non-Exception object.

@kpreisser kpreisser deleted the changeExceptionType branch January 10, 2019 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants