Exception Dealing with in C#

It has been observed seldom that a system operates successfully at its incredibly first endeavor. Errors are incredibly popular even though acquiring a system and are regarded as mistakes. The mistakes can be possibly compile time or run time.
Compile time mistakes are generally syntax mistakes and are detected ahead of the execution of system. Missing semicolons, Mismatch of brackets, misspelling of keywords and phrases and identifiers, terrible references and improper assignments are popular compile time mistakes. Run Time mistakes are manifest in the course of the execution of system. These mistakes do not let the successful execution of system and sometime sales opportunities to undesired outcomes. In contemporary programming, run time mistakes are also named exceptions. Divide by zero, invalid typecasting, invalid references, inability to obtain a source are some of the run time mistakes. Run time mistakes are regarded far more perilous as when compared to compile time mistakes. These are generally because of the invalid logic and seldom because of to syntax.
C# presents a incredibly productive process to take care of run time mistakes (Exceptions). When C# compiler encounters run time mistake, it results in an exception item and throws it. If exception is not caught and handled, the mistake information is displayed and system terminates instantly. To continue the execution of system, even mistake has occurred the exception must be caught and handled properly. In .Internet, exceptions are circumstances of the courses derived from Technique.Exception.

Exception is managing is accomplished working with- try….catch….ultimately syntax. We enclose the code in test block, which is likely to raise the exception, adopted by catch block. The catch block catches the exception thrown and handles it. Just about every catch block has the code to take care of the exception appropriately. At conclude we write the ultimately block- specifying the code that is usually executed no matter of whether or not the exception is thrown.



/////exception managing code


///the code to be executed ultimately whether exception occurred or not

A solitary test block can have many catch blocks, just about every handles the precise exception. But only 1 catch block is executed for each and every test block, out of many catch blocks. When an exception is occurred, catch blocks are examined 1 by 1 till the proper is located, that can take care of the exception. If no distinct catch block handles the exception, then only general catch block is executed.