O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multiple catch Blocks

If a try block contains code that can throw more than one type of exception object, (for example, DivideByZeroException as well as IndexOutOfRangeException), you can specify more than one catch block relating back to the same try block (as shown in Syntax Box 19.1). When an exception object is looking for a matching catch block, the possible catch blocks are inspected in the sequence in which they appear in the source code. The first matching catch block will handle the exception. After this matching catch block has been executed, all other related catch blocks are ignored, and the execution commences after the end of the last catch block.

Note

When multiple catch blocks are applied, the exception subclasses specified for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required