Skip to main content

Posts

Showing posts from February, 2011

Error Handling in try catch statement

Error Handling in try catch statement,  try      {           b=0;           c=a/b;      }  catch (Exception ex) {}  catch  // related exception{}  finally{}  which exception will catch first statement? try { int b = 0; int c = 10 / b; } catch (Exception e) { } catch(DivideByZeroException ae) { } finally { } Ans:- Numerous catch blocks are evaluated from top to bottom for each exception that is thrown, but only one catch block is actually executed. The order in which the catch blocks are inserted is important because.NET will jump to the first catch block that is polymorphically consistent with the thrown exception. Catch blocks for exception classes that are the most specialized and descending should come first. In your example, the exception's type—which acts as the starting point for all exceptions and is, therefore, polymorphically consistent with every exception thrown—is the initial catch. The finally block is also always executed after the try and catch blocks. A fina