1 Answers
We can use multiple catch blocks with a try statement. Each catch block can catch a different exception. The following code example shows how to implement multiple catch statements with a single try statement.
- using System;
- class MyClient {
- public static void Main() {
- int x = 0;
- int div = 0;
- try {
- div = 100 / x;
- Console.WriteLine(“Not executed line”);
- } catch (DivideByZeroException de) {
- Console.WriteLine(“DivideByZeroException”);
- } catch (Exception ee) {
- Console.WriteLine(“Exception”);
- } finally {
- Console.WriteLine(“Finally Block”);
- }
- Console.WriteLine(“Result is {0}”, div);
- }
- }