We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Saturday, May 16, 2015

Exceptions & Exception Handling in c#




-Generally under every program we will be comming across errors which are of 2 types:
     -Compile Time Errors
     -Run Time Errors

-A compile time error occurs due to the syntactical mistake that occurs in a program, these are not considered to be dangerous.


-A runtime error also known as an Exception occurs under a program while the execution of the program is taking place this can be due to various reasons like wrong implementation of logic, invalid input supplied to the program etc., these errors are considered to be dangerous because when they occur under the program the program terminates abnormally with out executing the next lines of code.

-What happens when an exception or runtime error occurs under a program ?
Ans: When ever an exception occurs in a program on a certain line, the execution of the program stops immediately on the line with out executing the next lines of code as well as displays an error msg related with the error.


-What is an Exception as a programmer ?
Ans: As a programmer every exception is a class which is defined under the system namaspace. The parent class for all these exeception classes is "Exception".


-How can we stop the abnormal termination that occurs when an exception occurs ?
Ans: To stop the abnormal termination that occurs when an exception occurs we are provided with an approach known as "Exception Handling", which allows you to stop the abnormal termination as well as can be used to display user friendly error msgs to the end users.


-How to perform Exception Handling within a program ?
Ans: To perform Exception Handling we were provided with 2 blocks of code known as "try..catch" blocks, which has to be used as following:

try
{
 -Statement which will cause the exception
 -Statement which are related with the exception and   should not execute when exception occurs
}
catch (<exception> <var>)
{
 -Statement which should execute only when the   exception occurs
}

No comments: