Catching Errors with Try and Catch
Errors can be catched using the try and catch block.
enclose your code where you think you will get an error in the try block
try
{
error code
}
catch
{
catch the error and display it
}
|
Catching and Handling exceptions
The .NET framework provides an Exception calss for working with exceptions.
Message: Returns a string representing the error message
Source: Returns the string representing the object that caused the error
StackTrace: Returns a string representing the method that were called just before the error occured
TargetSite: Returns a MethodBase oject representing the methods that caused the error
try
{
......
}
catch(Exception objException);
{
Response.Write(objException.Message);
Response.Write(objException.Source);
Response.Write(objException.StackTrace);
Response.Write(objException.TargetSite);
}
|