In this post, I am not going to talk about how to throw/re-throw exceptions or even write the best practices on Exception handling, but I will go on with some of the hidden facts of exception handling which you might want to know and later on will involve IL to check how exceptions are generated.
The Basics
Exception handling is one of the weakest section of CLR. Even though I like most of the things that CLR brings to us, but I definitely disagree if the exception handling is one amongst it. Even the exception handling as been evolved with the system is enhanced very well recently with the introduction of Uncatchable Exceptions, RuntimeWrappedException, code contacts etc. Lets discuss some of the major enhancements to the exception system.
The .NET exception handling is made up of three sections :
- try : In this segment you need to write only the portion which can potentially throw errors.
- catch : This section can overload based on the type of Exception and will be used to handle the exception which occurred in the Try block.
- finally : This block executes irrespective of try and catch. We write the clean up tasks here as it ensures to run even anything occurs.
Read Disclaimer Notice