This code is an eye opener to the way exceptions are handled in C#. At the face of it, it seems that the code will throw a runtime exception. But, thats were you are deceived! Since the division operation is hard-coded ( i.e. 15/0 ), the compiler throws a compiler error.This gives NO CHANCE for the catch block to be executed! However, if this condition was generated during runtime, it would be handled by the catch block. Eureka!!!
class ExceptionClass { static void Main() { try { Console.WriteLine(15/0); } catch(DivideByZeroException e) { Console.WriteLine("Exception throws:"+e); } } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|