Exception Handling in C#

Exception Handling in C#

It has been noticed hardly ever that a software runs productively at its pretty to start with endeavor. Problems are pretty common even though establishing a software and are considered as problems. The problems can be possibly compile time or run time.
Compile time problems are generally syntax problems and are detected before the execution of software. Missing semicolons, Mismatch of brackets, misspelling of key phrases and identifiers, poor references and poor assignments are common compile time problems. Run Time problems are occur all through the execution of software. These problems do not allow for the successful execution of software and someday qualified prospects to undesired success. In present day programming, run time problems are also known as exceptions. Divide by zero, invalid typecasting, invalid references, incapacity to accessibility a resource are some of the run time problems. Run time problems are considered more hazardous as when compared to compile time problems. These are generally because of the invalid logic and hardly ever because of to syntax.
C# provides a pretty productive process to tackle run time problems (Exceptions). Whenever C# compiler encounters run time error, it results in an exception item and throws it. If exception is not caught and taken care of, the error message is exhibited and software terminates immediately. To keep on the execution of software, even error has happened the exception will have to be caught and taken care of adequately. In .Internet, exceptions are situations of the classes derived from Method.Exception.

Exception is managing is completed utilizing- try….catch….finally syntax. We enclose the code in consider block, which is possible to raise the exception, adopted by catch block. The catch block catches the exception thrown and handles it. Every single catch block has the code to tackle the exception appropriately. At conclude we produce the finally block- specifying the code that is constantly executed regardless of whether or not or not the exception is thrown.
Attempt

/////code

catch

/////exception managing code

finally

///the code to be executed finally whether or not exception happened or not

A solitary consider block can have a number of catch blocks, every handles the specific exception. But only just one catch block is executed for every single consider block, out of a number of catch blocks. When an exception is happened, catch blocks are examined just one by just one till the acceptable is found, that can tackle the exception. If no certain catch block handles the exception, then only typical catch block is executed.

Comments are closed.