Your SlideShare is downloading. ×
Exception Handling Mechanism in .NET CLR
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Exception Handling Mechanism in .NET CLR


Published on

Published in: Education

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Presented by: 08-SE-59 08-SE-64 08-SE-69 08-SE-72
  • 2.
    • Analysis of the .NET CLR Exception Handling Mechanism
    • Fruja,N.G., Börger,E.
  • 3.
    • Introduction to CLR
    • Exceptions
    • Exception Handling
    • Exception Handling mechanism in .NET CLR
    • Conclusion
  • 4.
    • Primary Parts:
      • .NET Framework
      • Common Language Runtime (CLR)
    • What is CLR?
    • The Common Language Runtime ( CLR ) is a core component of Microsoft's .NET initiative. In the CLR, code is expressed in a form of byte code
  • 5.  
  • 6.
    • JIT allows code to run in a protected environment as managed code.
    • CLR also allows for enforcement of code access security.
    • Verification of type safety.
    • Improved “garbage collection”
  • 7.  
  • 8.
    • The term exception is shorthand for the phrase "exceptional event."
    • An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
    • Exception can result in:
      • Error occurred in execution time
      • Abnormal termination of program
      • Wrong execution result
  • 9.  
  • 10.
    • This class is the base class for all exceptions.
    • Two categories of exceptions exist under the base class Exception :
      • The pre-defined common language runtime exception classes; derived from SystemException .
      • The user-defined application exception classes derived from ApplicationException .
  • 11.
    • Exception Object:
      • When there is an exception, the .NET framework creates an object of type 'Exception' and 'throws' it.
      • contains information about the 'error.
    • throwing an exception
    • Explicit Exceptions
      • throw statement.
  • 12.
    • Syntax:
      • throw exception;
    • Can be used together with the try catch statement.
      • The try block contains the guarded code that may cause the exception.
      • The catch block contains the appropriate code to handle that exception.
  • 13.
          • <html><body> <script type=&quot;text/javascript&quot;> var x=prompt(&quot;Enter a number between 0 and 10:&quot;,&quot;&quot;); try   {   if(x>10)        throw &quot;Err1&quot;;    else if(x<0)         throw &quot;Err2&quot;;    else if(isNaN(x))         throw &quot;Err3&quot;;    }
  • 14.
    • catch(er)   {   if(er==&quot;Err1&quot;)     {     alert(&quot;Error! The value is too high&quot;);     }   if(er==&quot;Err2&quot;)     {     alert(&quot;Error! The value is too low&quot;);     }   if(er==&quot;Err3&quot;)     {     alert(&quot;Error! The value is not a number&quot;);     }   } </script> </body> </html>
  • 15.
    • Inner Exception Property:
      • The most current exception called inner exception.
      • stored in the inner exception property.
    • Outer Exception Property:
      • The outer exception is thrown in response to this inner exception.
    • The code that handles the outer exception can use the information from the earlier inner exception.
  • 16.
    • Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions , special conditions that change the normal flow of program execution.
    • e.g. In , .NET try, catch
    • are used to handle exceptions.
  • 17.
    • Termination model
    • Retry model
    • Resumption model
  • 18.
    • First popular mechanism
    • The code after that point, at which an exception occurs, will not be executed.
      • i.e. the execution is terminated at the point at which an exception occurs
  • 19.
  • 20.
    • The handler will try to clean up the environment resulted from the exception and will try to restart the execution.
    • The original environment at that point of execution should be restored.
  • 21. Restart point This part of the code will be executed again
  • 22.
    • The handler does the work of cleaning up the damage resulted because of the exception
    • Then control is transferred to the point next to the one where the execution flow was interrupted because of the exception and the execution continues from there on.
  • 23. Exception point and restart point
  • 24.  
  • 25.
    • A catch handler that can handle any type of exception.
    • A finally handler is executed under any circumstance, regardless whether an exception occurs or not and can be used to close critical resources such as files or handles.
    • A fault handler is called whenever an exception occurs but is not called as part of the normal control flow.
    • A filtered handler handles exceptions of a specified type (or subtype of the specified type) and is only called when such an exception was thrown.
  • 26.
    • The exception handling mechanism excCLR proceeds in three passes:
    • The StackWalk PASS
    • The Unwind PASS
    • The Leave PASS
  • 27.
    • There are three groups of possible handlers in a given frame during its StackWalk:
    • a catch/filter handler whose try block protects the program counter of the frame pointed by stackCursor .
    • a filter handler whose filter region contains pc of the frame pointed at by stackCursor .This corresponds to an outer exception.
  • 28.
    • When Unwinding, the EXC CLR searches for:
    • the matching target handler , i.e. the handler determined at the end of the Stack Walk pass (if any) – handler can be undef if the search in the Stack Walk has been exited because the exception was thrown in a filter region.
    • a matching finally/fault handler whose associated try block protects the pc.
    • a handler whose handler region contains pc.
    • a filter handler whose filter region contains pc .
  • 29.
    • In the Leave pass, the EXC CLR machine searches for:
    • F inally/catch/filter handlers that are “on the way” from the pc to the target.
  • 30.  
  • 31.
    • Exception is an event, that interrupts the normal flow of the program's instructions
    • Exception handling is a mechanism to handle the occurrence of exceptions.
    • .NET CLR handles exceptions using PASSES.
  • 32.
    • The StackWalk Pass, Unwind Pass and Leave Pass work together to provide the exception handling mechanism in CLR.