It has been observed hardly ever that a program operates properly at its very 1st endeavor. Errors are very popular although creating a program and are thought of as mistakes. The mistakes can be either compile time or operate time.
Compile time mistakes are frequently syntax mistakes and are detected ahead of the execution of program. Missing semicolons, Mismatch of brackets, misspelling of keywords and phrases and identifiers, negative references and inappropriate assignments are popular compile time mistakes. Operate Time mistakes are manifest in the course of the execution of program. These mistakes do not allow the profitable execution of program and someday leads to undesired success. In fashionable programming, operate time mistakes are also named exceptions. Divide by zero, invalid typecasting, invalid references, incapacity to entry a resource are some of the operate time mistakes. Operate time mistakes are thought of additional perilous as in comparison to compile time mistakes. These are frequently because of the invalid logic and hardly ever because of to syntax.
C# delivers a very effective strategy to manage operate time mistakes (Exceptions). Whenever C# compiler encounters operate time error, it creates an exception object and throws it. If exception is not caught and managed, the error information is exhibited and program terminates promptly. To keep on the execution of program, even error has transpired the exception need to be caught and managed properly. In .Net, exceptions are scenarios of the classes derived from Process.Exception.
Exception is dealing with is carried out working with- try….catch….eventually syntax. We enclose the code in test block, which is likely to raise the exception, followed by capture block. The capture block catches the exception thrown and handles it. Every capture block has the code to manage the exception correctly. At close we publish the eventually block- specifying the code that is constantly executed regardless of regardless of whether or not the exception is thrown.
/////exception dealing with code
///the code to be executed eventually regardless of whether exception transpired or not
A solitary test block can have a number of capture blocks, each and every handles the certain exception. But only one capture block is executed for every test block, out of a number of capture blocks. When an exception is transpired, capture blocks are examined one by one until the suitable is observed, that can manage the exception. If no unique capture block handles the exception, then only general capture block is executed.