Exception handling is a method for handling runtime errors. C# includes the following built-in support for handling exceptions during program execution:
• Finally • Throw
• Try • Catch
A try block is a block of code for which specific exceptions are enabled. If any of the exceptions occur during runtime, the control flow jumps to the first matching catch block.
With a catch block, the program catches an exception where you want to handle the issue. It also includes a set of code to execute if an exception occurs, or it can simply catch the exception and do nothing.
The finally block is always executed regardless of an exception being thrown. If the program does not find any exceptions, it exits immediately after the try block or immediately after the catch block.
This block allows the program to throw an error whenever it encounters one. You can also re throw an exception from a catch block and pass it to the caller and let them handle it as they want to fit.