Handling Exceptions
While setting up try/catch/finally blocks and catching the generic exception is better than not catching errors at all, there are various methods of handling errors to make code more robust. This section shows how to handle errors in a couple different ways, including handling multiple exception types, handling and passing on exceptions, and recovering from exceptions.
Handling Multiple Exceptions
Previous examples showed how to catch the generic exception, System.Exception. Generic error handling isn't adequate in most situations. That's why C# provides the ability to specify multiple exception handlers for a single try block.
This works by placing additional catch blocks below the try block. catch blocks should be ordered ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.