Code Design - Event call, Catch exceptions or not?
-
Hey, i was working on some API for networking when i implemented some sort of logging and Reporting, in certain situations when all of the sudden my Test project in WPF didn't worked as expected. After some debugging i found a Cross-Thread exception that was caused by some bindings. The API is using some High Level of threading and Tasking support. The problem was that i was attached to a Event that was trigger in a Non-Dispatcher Thread, and inside my ViewModel i did not synchronized the code. The Whole application was still running ( AppDomain had some global exception Handling ) but the point is, this external exception ( as seen from the API side ) had noting to do with the API but prevented it from working by throwing an Exception and stops the execution of the code after the Event Trigger. I learned due my time as a Developer that some sort of "General" exception catching should be prevented where possible. This does not mean an empty TryCatch block ( What is actually even very Bad ). So my Question is: Should i break this Design guide and more, should i catch Exceptions in general when i Invoke an event? The event handler could Throw some exceptions what i do not expect and i should not worry about. And last but not least: If jes, what to do when we catch an event?
-
Hey, i was working on some API for networking when i implemented some sort of logging and Reporting, in certain situations when all of the sudden my Test project in WPF didn't worked as expected. After some debugging i found a Cross-Thread exception that was caused by some bindings. The API is using some High Level of threading and Tasking support. The problem was that i was attached to a Event that was trigger in a Non-Dispatcher Thread, and inside my ViewModel i did not synchronized the code. The Whole application was still running ( AppDomain had some global exception Handling ) but the point is, this external exception ( as seen from the API side ) had noting to do with the API but prevented it from working by throwing an Exception and stops the execution of the code after the Event Trigger. I learned due my time as a Developer that some sort of "General" exception catching should be prevented where possible. This does not mean an empty TryCatch block ( What is actually even very Bad ). So my Question is: Should i break this Design guide and more, should i catch Exceptions in general when i Invoke an event? The event handler could Throw some exceptions what i do not expect and i should not worry about. And last but not least: If jes, what to do when we catch an event?