1 / 20

Tracing, Logging, and Error Handling MacDonald Ch. 8

Tracing, Logging, and Error Handling MacDonald Ch. 8. MIS 424 Professor Sandvig. Today. Error Handling Objective Exception Class Trapping Try Catch block Page-level trapping Application-level trapping Global.asax Web.config. Error Handling. Goal: User NEVER sees yellow screen!!

brasen
Download Presentation

Tracing, Logging, and Error Handling MacDonald Ch. 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tracing, Logging, and Error HandlingMacDonald Ch. 8 MIS 424 Professor Sandvig

  2. Today • Error Handling • Objective • Exception Class • Trapping • Try Catch block • Page-level trapping • Application-level trapping • Global.asax • Web.config

  3. Error Handling • Goal: • User NEVER sees yellow screen!! • Handle errors gracefully • Example: WWU, ThinkGeek • Implementation: • Robust programming • Validate all user inputs • Handle foreseeable problems • Trap all errors • Handle gracefully • Error Pages • Log errors

  4. Error Handling A good programmer is someone who always looks both ways before crossing a one-way street. Doug Linder systems administrator

  5. Exception Class • Exception object thrown when exception occurs • Contains info about problem • Two flavors: • General (exception base class) • Specific (sqlException class)

  6. Exception Class • Can also customize exceptions • Provide specific information • Select appropriate exception and add custom message • List of exceptions • Example: Dog class (from 324)

  7. Exception Class • Set dog weight:

  8. ASP.NET Error Handling Tools Catch errors at three levels: • Line: Try...Catch…Finally blocks • Page: Page_error() • Application: Global.asax

  9. Line-level Error Handling • Try Catch Block • Wrap high-risk code • Database, web services • All code that interacts with external data • Benefits • Provide handlers • Graceful response • Log error • Continue code execution • Easy to implement

  10. Try Catch Block Syntax try { // problematic code } catch (Exception e) { // error handler code }

  11. Try Catch Block • Where: • Catch in .aspx page • Errors will bubble up • Provide user with nice message • Log error

  12. Exception Handling • Can trap by type of exception • Trap specific first, then general • Syntax: Catch objEx as FormatException { handler } Catch objEx as OleDbException { Handler } Catch objEx as Exception { Handler }

  13. Exception Handling • Exceptions types • Listed in MSDN documentation • System.Data.SqlClientSqlException Class • Try Catch • Example: source, output • WriteErrorLog.cs

  14. Page Level error trapping • Catches unhandled exceptions on Page void Page_Error() { //handle error (write to log, redirect, etc.) } • Example: source, output

  15. Page_Error • Limitation • Page execution is terminated • Labels not displayed • User sees text error message • Graceful response: • Redirect user to an error page

  16. Application Level • Catches all unhandled exceptions • Including 404s • Examples: Amazon, Netflix • Two options: • Global.asax • Web.Config file

  17. Application Level • Global.asax • Handles application events • Application start • Application end • Session start • Session end • Application_Error() • UnhandledError.aspx source, output

  18. Application Level • Web.config • Last in line • Redirects user to an error page • Syntax: <customErrorsdefaultRedirect="http://..." mode="On"> <error statusCode="404" redirect="filenotfound.htm" /> </customErrors>

  19. Application Level • Web.config • Disadvantage: cannot get error details for log • Global.asax is better option • Error details accessible

  20. Summary • Error Trapping • Objectives • Handle exceptions gracefully • Record details in log file • 3 Levels • Line - Try Catch Block • Page - Page_Error() • Application • Global.asaxApplication_Error • web.config

More Related