fix: unwrap exceptions thrown in event handlers#385
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #383 by ensuring that exceptions thrown from event handlers are not wrapped in TargetInvocationException when raised through mock events. The fix unwraps the inner exception during event handler invocation.
Changes:
- Modified
MockRegistration.Raiseto catch and unwrapTargetInvocationExceptionwhen invoking event handlers - Added test case verifying that exceptions from event subscriptions are properly thrown without wrapping
- Minor formatting improvements to method invocation calls
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Source/Mockolate/MockRegistration.cs | Added try-catch block to unwrap TargetInvocationException and preserve original exceptions from event handlers; minor formatting changes |
| Tests/Mockolate.Tests/MockEvents/RaiseTests.cs | Added test verifying exceptions from event handlers are not wrapped |
🚀 Benchmark ResultsDetails
|
|
|
This is addressed in release v1.0.1. |



This PR ensures that exceptions thrown from event handlers are not wrapped in
TargetInvocationExceptionwhen raised through mock events. The fix unwraps the inner exception during event handler invocation.Key Changes:
MockRegistration.Raiseto catch and unwrapTargetInvocationExceptionwhen invoking event handlers