we can use multiple Catches block with every try but when any Exceptions is throw by debugger so every catches match this exception type with their signature and catch the exception by any single catch block so that means we can use multiple catches blocks but only one can executed at once like:
- 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);
- }
- }
No comments:
Post a Comment