#866 – A catch Block Without Arguments Catches All Exceptions
You typically include an argument in a catch block that indicates the type of exception to catch. catch (FileNotFoundException fnfExc) { Console.WriteLine(string.Format("Hey, we can't find file {0}!",...
View Article#867 – Including Several catch Blocks
You can include several catch blocks in a single try-catch statement, each catch block set up to catch a different kind of exception. try { DoSomething(5); } catch (FileNotFoundException noFileExc) {...
View Article#868 – List Most Specific Exception Types First
When you include more than one catch blocks as part of a try-catch statement, you must list the most specific exception types first. When an exception occurs, the type of the exception object is...
View Article#869 – Example of Catching an Exception Thrown by the .NET Framework
Below is a complete example that shows how we might catch an exception thrown by the .NET Framework. Our Dog class builds a list of all dogs created and allows you to retrieve a dog by index. public...
View Article#870 – Where Execution Continues when an Exception Is Caught
When an exception is thrown that you catch in a catch block, the code in the catch block will execute. Once all of the code in the catch block executes, execution will continue with the first line...
View Article#873 – Full Example of Throwing and Catching an Exception
Below is a complete example of throwing an exception from a method and catching/handling that exception further up the call stack. Code for Dog class that throws an exception if we ask a dog to bark...
View Article#880 – Catching Different Exception Types at Different Levels
You can include catch blocks at different points in the call stack, to catch different types of exceptions. In the example below, Main calls CreateSomeDogs, which in turn creates Dog instances and...
View Article#889 – Catching Exceptions that Derive from a Common Base Type
When you specify an exception type to catch in a handler, the handler will catch all exceptions whose type matches the specified type. It will also catch exceptions where the exception object’s type...
View Article#899 – Exception Type Variable in a catch Block Is Optional
In a catch block that specifies a particular exception type to catch, you’ll typically include a named variable representing the exception object that is caught. Using this variable, code within your...
View Article#911 – finally Block Execution When Exception Is Rethrown
Recall that if an exception is caught in a catch block, an associated finally block will execute after the execution of the catch block. If the catch block rethrows the exception, the finally block...
View Article