Click Here Ads

Friday, September 4, 2009

Error...Chapter 9 for IP

At the 1st,
4 type of Error
i. Parser Error
 - Caused by Incorrect syntax/ bad grammar within HTML/ ASP .Net Page
 eg. Textb ID="txtName" runat="server"/>

ii. Compilation Error
 - Cause by syntax error, but different with parser error, it is occurs due to the statements are not recognized by language compiler, rather than HTML/ ASP .Net.
* raised when the page in the process being compiled( b4 compile being start )
eg. txtName.value = "super";
cant recognized by compiler, textbox don't have value this probability.

iii. Configuration Error
 - Cause by problem in either Web Config/ Machine Config File.
eg.
 missing close statement, XML must have < xxx> or

iv. Runtime Error / Logical Error
- Occur during Runtime, after the page is successfully.
- Cant detect by Compiler ( difference between other 3 errors)

What is Exception??
The exception are any error condition or unexpected behavior that occurs during the execution of a program.
It disrupts the normal flow of execution.

Exception Handling Methods
Page-Level Error Handling 
try...catch...finally
eg. try
      { your statement }
     catch ( Exception e)
     { statements occur when error occur}
     finally
     { statements in this block is "FORCED" to be executed irrespective of the fact that an exception has been          
      raised}
Page_Error()
eg.
protected void Page_Error( object sender, EventArgs e)
{
    Exception ex = Server.GetLastError().GetBaseException();
    Response.Write(ex.Message.ToString());
    Server.ClearError();
}
 When page error, The error message will be display by response.write.
 you also can redirect to other page by using this method.

Application_Error() Method
In Global.asax, we can find 1 event handler name as Application_Error()
We can write code inside the event.

Different between this 3 methods is :
try...catch...finally  - within a block of code
Page_Error() - within a page
Application_Error - within application


Benefits Custom Error Page in an application
users might not understand technical details of exception, so we can provide them a user-friendly error page.

No comments:

Post a Comment