SlideShare ist ein Scribd-Unternehmen logo
1 von 17
•Error occurred in execution time


 •Abnormal termination of program


 • Wrong execution result




11/19/2012     Presented by: Neelesh Shukla   1
Is it a best practice to handle every
                 error?
  No, it is not best practice to handle every error. It
    degrades the performance.
  You should use Error Handling in any of following
    situation otherwise try to avoid it.
 1.     If you can able to recover error in the catch block
 2.     To write clean-up code that must execute even if
      an exception occur
 3.     To record the exception in event log or sending
      email.
11/19/2012       Presented by: Neelesh Shukla                 2
Exception Handling
         There are three ways to handle exceptions/errors in
                                           ASP.NET

           1) Try-Catch block.              This is also called Structured
                                             Exception Handling (SEH).

           2) Error Events.                 They are page level or application
                                             level error events.

           3) Custom Error Page. This is used for any unhandled
                                  error.
    11/19/2012          Presented by: Neelesh Shukla                          3
1) What is try Block?
  Try Block consist of code that might generate error.


  Try Block must be associated with one or more catch
     block or by finally block.

  Try Block need not necessarily have a catch Block
     associated with it but in that case it must have a finally
     Block associate with it.


11/19/2012        Presented by: Neelesh Shukla                    4
What is catch Block?
  Catch Block is used to recover from error generated in
   try Block.
  In case of multiple catch Block, only the first matching
   catch Block is executed.
  When you write multiple catch block you need to
   arrange them from specific exception type to more
   generic type.
  When no matching catch block are able to handle
   exception, the default behavior of web page is to
   terminate the processing of the web page.

11/19/2012      Presented by: Neelesh Shukla                  5
What is finally Block?
 Finally Block contains the code that always executes, whether
    or not any exception occurs.
   When to use finally Block? - You should use finally block to
    write cleanup code. i.e. you can write code to close files,
    database connections, etc.
   Only One finally block is associated with try block.
   Finally block must appear after all the catch block.
    If there is a transfer control statement such as goto, break or
    continue in either try or catch block the transfer happens
    only after the code in the finally block is executed.
    If you use transfer control statement in finally block, you will
    receive compile time error.
11/19/2012          Presented by: Neelesh Shukla                    6
Example of Try-Catch-Finally
       Try
       {
       --------
       --------
       --------
       }
       Catch(Exception ex)
       {
       -------
       -------
       }
       Finally
       {
       ----
       }
11/19/2012            Presented by: Neelesh Shukla   7
System-Defined Exception
  DivideByZero Exception
  NullReference Exception
  IndexOutOfRange Exception
  ArrayTypeMismatch Exception
  Arithmetic Exception
  Exception etc.




11/19/2012        Presented by: Neelesh Shukla   8
Exception class object properties
  Message: Get the error message.
  Source: Set or get the name of the application or object
   that causes the exception.
  StackTrace: Get a string representation of the frame on
   call stack at the time of current exception thrown.
  TargetSite: Get the current method that throws
   exception.
  InnerException: Get the system.exception instance
   that causes the current exception.

11/19/2012      Presented by: Neelesh Shukla                  9
In general, you will not be able to plan for,
catch and recover from every possible
exception that could occur within a page.
ASP.NET helps by offering two techniques to
handle page-level errors :

  Error Events
  Custom Error Page.




11/19/2012        Presented by: Neelesh Shukla   10
2)Error Events
 They are page level or application level error events:-
  Page_Error()
  Application_Error()




11/19/2012        Presented by: Neelesh Shukla             11
Page_Error()
 private void Page_Error(object sender, EventArgs e)
   {
      Exception ex = Server.GetLastError();
      Response.Write("<h1>An error has occurred</h1>");
      Response.Write("<h2>" + ex.Message + "</h2>");
      Response.Write("<pre>" + ex.StackTrace +
   "</pre>");
      Context.ClearError();
   }
 Note: This event fire if the page control is not disposed.
11/19/2012      Presented by: Neelesh Shukla                  12
Application_Error()
 The Error event of the Application class is fired when an exception is left
   unhandled. The handler is usually found in Global.asax

void Application_Error(object sender, EventArgs e)
  {
      // Code that runs when an unhandled error occurs

    System.Exception ex = Context.Server.GetLastError();

    ExceptionLog.MessageDetails(ex);

    // Code for handling error on Application level

    Response.Write("Handled error from Application <br>");
    Server.ClearError();
  }
Note: In the code above that ClearError() method should always be called after the exception has
   been handled. If the ClearError() has not been cleared, the exception will still show up on the
   client's browser.
    11/19/2012               Presented by: Neelesh Shukla                                     13
3) Custom Error Page
  First change the Application_Error method to the following:
   protected void Application_Error(object sender, EventArgs e)
   {
        System.Exception ex = Context.Server.GetLastError();
        ExceptionLog.MessageDetails(ex);
   }
  Notice that I have removed the Server.ClearError();
  Then add a customErrors section to your web.config file. This
   should be nested within the system.web element
  Add a new custom error page “Error.aspx” into your project to
   display a custom Error page, if any unhandled error occurs.


11/19/2012        Presented by: Neelesh Shukla                     14
<system.web>
      .....
     <customErrors mode="On" defaultRedirect="Error.aspx">
     //<error statusCode="404" redirect="Error404.aspx" />
     </customErrors>
     </system.web>

Note: Details of status code can be found at http://httpstatus.es

 To customize the default error page, one will have to change the default
     configuration settings of the application.
     There are three error modes in which an ASP.Net application can work:

1.         Off Mode
2.         On Mode
3.         RemoteOnly Mode
     11/19/2012         Presented by: Neelesh Shukla                   15
1. When the error attribute is set to "Off", ASP.Net uses
    its default error page for both local and remote users
    in case of an error.
 2. In case of "On" Mode, ASP.Net uses user-defined
    custom error page instead of its default error page for
    both local and remote users. If a custom error page is
    not specified, ASP.Net shows the error page
    describing how to enable remote viewing of errors.
 3. The Error mode attribute determines whether or not
    an ASP.Net error message is displayed. By default, the
    mode value is set to "RemoteOnly".



11/19/2012      Presented by: Neelesh Shukla              16
11/19/2012   Presented by: Neelesh Shukla   17

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Exceptional Handling in Java
Exceptional Handling in JavaExceptional Handling in Java
Exceptional Handling in Java
 
Java applets
Java appletsJava applets
Java applets
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Exception handling
Exception handling Exception handling
Exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 

Andere mochten auch

Exception handling
Exception handlingException handling
Exception handlingIblesoft
 
Asp.NET Handlers and Modules
Asp.NET Handlers and ModulesAsp.NET Handlers and Modules
Asp.NET Handlers and Modulespy_sunil
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34myrajendra
 
Access Protection
Access ProtectionAccess Protection
Access Protectionmyrajendra
 
Effective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and InterfacesEffective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and Interfacesİbrahim Kürce
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRKiran Munir
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...IAEME Publication
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 

Andere mochten auch (20)

Exception handling
Exception handlingException handling
Exception handling
 
Asp.NET Handlers and Modules
Asp.NET Handlers and ModulesAsp.NET Handlers and Modules
Asp.NET Handlers and Modules
 
Exception handling
Exception handlingException handling
Exception handling
 
Error handling in ASP.NET
Error handling in ASP.NETError handling in ASP.NET
Error handling in ASP.NET
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
 
Debugging in .Net
Debugging in .NetDebugging in .Net
Debugging in .Net
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34
 
Java exception
Java exception Java exception
Java exception
 
Access Protection
Access ProtectionAccess Protection
Access Protection
 
Effective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and InterfacesEffective Java - Chapter 4: Classes and Interfaces
Effective Java - Chapter 4: Classes and Interfaces
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Exception Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLRException Handling Mechanism in .NET CLR
Exception Handling Mechanism in .NET CLR
 
Debugging
DebuggingDebugging
Debugging
 
Java keywords
Java keywordsJava keywords
Java keywords
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...
EVALUATION OF PROCESSES PARAMETER AND MECHANICAL PROPERTIES IN FRICTION STIR ...
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
Packages in java
Packages in javaPackages in java
Packages in java
 

Ähnlich wie Exception handling in asp.net

Exceptionhandelingin asp net
Exceptionhandelingin asp netExceptionhandelingin asp net
Exceptionhandelingin asp netArul Kumar
 
Exception handling
Exception handlingException handling
Exception handlingzindadili
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix Solutions
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsRandy Connolly
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 
iOS Mobile App crash - Analysis
iOS Mobile App crash - Analysis iOS Mobile App crash - Analysis
iOS Mobile App crash - Analysis Murali krishna
 
Exception handling in asp.net
Exception handling in asp.netException handling in asp.net
Exception handling in asp.netLearningTech
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and DebuggingRich Helton
 
Node.JS error handling best practices
Node.JS error handling best practicesNode.JS error handling best practices
Node.JS error handling best practicesYoni Goldberg
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Exception Hnadling java programming language
Exception Hnadling  java programming languageException Hnadling  java programming language
Exception Hnadling java programming languageushakiranv110
 

Ähnlich wie Exception handling in asp.net (20)

Exceptionhandelingin asp net
Exceptionhandelingin asp netExceptionhandelingin asp net
Exceptionhandelingin asp net
 
Java bad coding practices
Java bad coding practicesJava bad coding practices
Java bad coding practices
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Exception handling
Exception handlingException handling
Exception handling
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding Standards
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
iOS Mobile App crash - Analysis
iOS Mobile App crash - Analysis iOS Mobile App crash - Analysis
iOS Mobile App crash - Analysis
 
Exception handling in asp.net
Exception handling in asp.netException handling in asp.net
Exception handling in asp.net
 
JAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdfJAVA PPT -4 BY ADI.pdf
JAVA PPT -4 BY ADI.pdf
 
C# Security Testing and Debugging
C# Security Testing and DebuggingC# Security Testing and Debugging
C# Security Testing and Debugging
 
Node.JS error handling best practices
Node.JS error handling best practicesNode.JS error handling best practices
Node.JS error handling best practices
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?
 
Exception Hnadling java programming language
Exception Hnadling  java programming languageException Hnadling  java programming language
Exception Hnadling java programming language
 
Java exeptions
Java exeptionsJava exeptions
Java exeptions
 
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
CS3391 -OOP -UNIT – III  NOTES FINAL.pdfCS3391 -OOP -UNIT – III  NOTES FINAL.pdf
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
 
Exception handling
Exception handlingException handling
Exception handling
 
Presentation1
Presentation1Presentation1
Presentation1
 

Kürzlich hochgeladen

Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstepmitaliverma221
 
gatiin-namaa-meeqa .pdf
gatiin-namaa-meeqa                        .pdfgatiin-namaa-meeqa                        .pdf
gatiin-namaa-meeqa .pdfDesalechali1
 
Introduction to Fashion Designing for all
Introduction to Fashion Designing for allIntroduction to Fashion Designing for all
Introduction to Fashion Designing for allMuhammadDanishAwan1
 
The Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue ZonesThe Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue ZonesThe Clean Living Project
 
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...rajveerescorts2022
 
📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call GirlsNitya salvi
 
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurZirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurSheetaleventcompany
 
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime TirunelveliTirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelvelimeghakumariji156
 
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...Sheetaleventcompany
 
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...Sheetaleventcompany
 
Ladies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdfLadies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdfShort Good Quotes
 
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...Pooja Nehwal
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...rajveermohali2022
 
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime TumkurTumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkurmeghakumariji156
 
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...rajveermohali2022
 
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)delhi24hrs1
 
UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION
 UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION
UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATIONChandrakantDivate1
 
I am Independent Call girl in noida at chepest price Call Me 8826255397
I am Independent Call girl in noida at chepest price Call Me 8826255397I am Independent Call girl in noida at chepest price Call Me 8826255397
I am Independent Call girl in noida at chepest price Call Me 8826255397Riya Singh
 
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...Pooja Nehwal
 
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Nitya salvi
 

Kürzlich hochgeladen (20)

Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Service 7738596112 Free Delivery 24x7 at Your Doorstep
 
gatiin-namaa-meeqa .pdf
gatiin-namaa-meeqa                        .pdfgatiin-namaa-meeqa                        .pdf
gatiin-namaa-meeqa .pdf
 
Introduction to Fashion Designing for all
Introduction to Fashion Designing for allIntroduction to Fashion Designing for all
Introduction to Fashion Designing for all
 
The Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue ZonesThe Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue Zones
 
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
Zirakpur Call Girls ✅ Just Call ☎ 9878799926☎ Call Girls Service In Mohali Av...
 
📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls📞 Contact Number 8617370543VIP Hardoi Call Girls
📞 Contact Number 8617370543VIP Hardoi Call Girls
 
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service ZirakpurZirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
Zirakpur Call Girls Service ❤️🍑 7837612180 👄🫦Independent Escort Service Zirakpur
 
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime TirunelveliTirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
Tirunelveli Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tirunelveli
 
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
PREET❤️Call girls in Jalandhar ☎️8264406502☎️ Call Girl service in Jalandhar☎...
 
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
💚Call Girl In Amritsar 💯Anvi 📲🔝8725944379🔝Amritsar Call Girls No💰Advance Cash...
 
Ladies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdfLadies kitty party invitation messages and greetings.pdf
Ladies kitty party invitation messages and greetings.pdf
 
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...
Andheri East ) Call Girls in Mumbai Phone No 9004554577, Vashi Call Girls Ser...
 
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
Kharar Call Girls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort Se...
 
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime TumkurTumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
Tumkur Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tumkur
 
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...
Zirakpur Call GIrls Service✔️ 9915851334 ✔️Call Now Ranveer📲 Zirakpur Escort ...
 
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)
Cheap Rate ✨➥9582086666▻✨Call Girls In Gurgaon Sector 10 (Gurgaon)
 
UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION
 UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION
UNIVERSAL HUMAN VALUES - INTRODUCTION TO VALUE EDUCATION
 
I am Independent Call girl in noida at chepest price Call Me 8826255397
I am Independent Call girl in noida at chepest price Call Me 8826255397I am Independent Call girl in noida at chepest price Call Me 8826255397
I am Independent Call girl in noida at chepest price Call Me 8826255397
 
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...
Mahim Call Girls in Bandra 7738631006, Sakinaka Call Girls agency, Kurla Call...
 
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
Just Call Vip call girls Etawah Escorts ☎️8617370543 Two shot with one girl (...
 

Exception handling in asp.net

  • 1. •Error occurred in execution time •Abnormal termination of program • Wrong execution result 11/19/2012 Presented by: Neelesh Shukla 1
  • 2. Is it a best practice to handle every error?  No, it is not best practice to handle every error. It degrades the performance.  You should use Error Handling in any of following situation otherwise try to avoid it. 1. If you can able to recover error in the catch block 2. To write clean-up code that must execute even if an exception occur 3. To record the exception in event log or sending email. 11/19/2012 Presented by: Neelesh Shukla 2
  • 3. Exception Handling  There are three ways to handle exceptions/errors in ASP.NET  1) Try-Catch block. This is also called Structured Exception Handling (SEH).  2) Error Events. They are page level or application level error events.  3) Custom Error Page. This is used for any unhandled error. 11/19/2012 Presented by: Neelesh Shukla 3
  • 4. 1) What is try Block?  Try Block consist of code that might generate error.  Try Block must be associated with one or more catch block or by finally block.  Try Block need not necessarily have a catch Block associated with it but in that case it must have a finally Block associate with it. 11/19/2012 Presented by: Neelesh Shukla 4
  • 5. What is catch Block?  Catch Block is used to recover from error generated in try Block.  In case of multiple catch Block, only the first matching catch Block is executed.  When you write multiple catch block you need to arrange them from specific exception type to more generic type.  When no matching catch block are able to handle exception, the default behavior of web page is to terminate the processing of the web page. 11/19/2012 Presented by: Neelesh Shukla 5
  • 6. What is finally Block?  Finally Block contains the code that always executes, whether or not any exception occurs.  When to use finally Block? - You should use finally block to write cleanup code. i.e. you can write code to close files, database connections, etc.  Only One finally block is associated with try block.  Finally block must appear after all the catch block.  If there is a transfer control statement such as goto, break or continue in either try or catch block the transfer happens only after the code in the finally block is executed.  If you use transfer control statement in finally block, you will receive compile time error. 11/19/2012 Presented by: Neelesh Shukla 6
  • 7. Example of Try-Catch-Finally Try { -------- -------- -------- } Catch(Exception ex) { ------- ------- } Finally { ---- } 11/19/2012 Presented by: Neelesh Shukla 7
  • 8. System-Defined Exception  DivideByZero Exception  NullReference Exception  IndexOutOfRange Exception  ArrayTypeMismatch Exception  Arithmetic Exception  Exception etc. 11/19/2012 Presented by: Neelesh Shukla 8
  • 9. Exception class object properties  Message: Get the error message.  Source: Set or get the name of the application or object that causes the exception.  StackTrace: Get a string representation of the frame on call stack at the time of current exception thrown.  TargetSite: Get the current method that throws exception.  InnerException: Get the system.exception instance that causes the current exception. 11/19/2012 Presented by: Neelesh Shukla 9
  • 10. In general, you will not be able to plan for, catch and recover from every possible exception that could occur within a page. ASP.NET helps by offering two techniques to handle page-level errors :  Error Events  Custom Error Page. 11/19/2012 Presented by: Neelesh Shukla 10
  • 11. 2)Error Events They are page level or application level error events:-  Page_Error()  Application_Error() 11/19/2012 Presented by: Neelesh Shukla 11
  • 12. Page_Error() private void Page_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Write("<h1>An error has occurred</h1>"); Response.Write("<h2>" + ex.Message + "</h2>"); Response.Write("<pre>" + ex.StackTrace + "</pre>"); Context.ClearError(); } Note: This event fire if the page control is not disposed. 11/19/2012 Presented by: Neelesh Shukla 12
  • 13. Application_Error()  The Error event of the Application class is fired when an exception is left unhandled. The handler is usually found in Global.asax void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs System.Exception ex = Context.Server.GetLastError(); ExceptionLog.MessageDetails(ex); // Code for handling error on Application level Response.Write("Handled error from Application <br>"); Server.ClearError(); } Note: In the code above that ClearError() method should always be called after the exception has been handled. If the ClearError() has not been cleared, the exception will still show up on the client's browser. 11/19/2012 Presented by: Neelesh Shukla 13
  • 14. 3) Custom Error Page  First change the Application_Error method to the following: protected void Application_Error(object sender, EventArgs e) { System.Exception ex = Context.Server.GetLastError(); ExceptionLog.MessageDetails(ex); }  Notice that I have removed the Server.ClearError();  Then add a customErrors section to your web.config file. This should be nested within the system.web element  Add a new custom error page “Error.aspx” into your project to display a custom Error page, if any unhandled error occurs. 11/19/2012 Presented by: Neelesh Shukla 14
  • 15. <system.web> ..... <customErrors mode="On" defaultRedirect="Error.aspx"> //<error statusCode="404" redirect="Error404.aspx" /> </customErrors> </system.web> Note: Details of status code can be found at http://httpstatus.es  To customize the default error page, one will have to change the default configuration settings of the application. There are three error modes in which an ASP.Net application can work: 1. Off Mode 2. On Mode 3. RemoteOnly Mode 11/19/2012 Presented by: Neelesh Shukla 15
  • 16. 1. When the error attribute is set to "Off", ASP.Net uses its default error page for both local and remote users in case of an error. 2. In case of "On" Mode, ASP.Net uses user-defined custom error page instead of its default error page for both local and remote users. If a custom error page is not specified, ASP.Net shows the error page describing how to enable remote viewing of errors. 3. The Error mode attribute determines whether or not an ASP.Net error message is displayed. By default, the mode value is set to "RemoteOnly". 11/19/2012 Presented by: Neelesh Shukla 16
  • 17. 11/19/2012 Presented by: Neelesh Shukla 17