Exception,Handling,has,been,ob computer Exception Handling in C#
Gone are those times when the companies and the organisations didn't need a hi-tech system to handle them. Owing to the considerable increase in the business sector and thus, an enormous increase in the complexity of the organisational struc ----------------------------------------------------------Permission is granted for the below article to forward,reprint, distribute, use for ezine, newsletter, website,offer as free bonus or part of a product for sale as longas no changes a
It has been observed rarely thata program runs successfully at its very first attempt. Mistakes are very commonwhile developing a program and are considered as errors. The errors can beeither compile time or run time.Compile time errors are generallysyntax errors and are detected before the execution of program. Missingsemicolons, Mismatch of brackets, misspelling of keywords and identifiers, badreferences and improper assignments are common compile time errors. Run Timeerrors are occur during the execution of program. These errors do not allow thesuccessful execution of program and sometime leads to undesired results. Inmodern programming, run time errors are also called exceptions. Divide by zero,invalid typecasting, invalid references, inability to access a resource aresome of the run time errors. Run time errors are considered more dangerous ascompared to compile time errors. These are generally due the invalid logic andrarely due to syntax.C# provides a very efficient method to handle run timeerrors (Exceptions). Whenever C# compiler encounters run time error, it createsan exception object and throws it. If exception is not caught and handled, theerror message is displayed and program terminates immediately. To continue theexecution of program, even error has occurred the exception must be caught andhandled properly. In .NET, exceptions are instances of the classes derived fromSystem.Exception.Exception ishandling is done using- try .catch .finally syntax. We enclose the code in try block,which is likely to raise the exception, followed by catch block. The catchblock catches the exception thrown and handles it. Every catch block has thecode to handle the exception appropriately. At end we write the finally block-specifying the code that is always executed regardless of whether or not theexception is thrown.try{/////code;}catch {/////exception handling code;}finally{///the code to be executed finally whether exception occurred or not;}A single tryblock can have multiple catch blocks, each handles the specific exception. Butonly one catch block is executed for every try block, out of multiple catchblocks. When an exception is occurred, catch blocks are examined one by one till the appropriate is found, thatcan handle the exception. If no particular catch block handles the exception,then only general catch block is executed.
Exception,Handling,has,been,ob