Codebase Dynamic rewriting and Exception Handling RRS feed

  • General discussion

  • If an exception is thrown and the user programmer maintains catching it over and over.  A re-writable or rewriting DotNet library adhoc to Exceptions and Exception Handling.  This alleviate the performance slowdown and may not be a security liability for the application.  CLR could use a tiny dynamic re-writing because it is learning new things once its running.

    I was unsure if this discussion would be more kind in DotNet BCL.

    Basketball is kewl with PCs
    Thursday, November 17, 2011 2:40 PM

All replies

  • The managed programming model uses the concept of exceptions to notify callers up the stack about error conditions during run time. Typically, the caller of a method would know what kind of exception the method may throw (or raise), and, accordingly, the call is made from within the confines of a try block with an associated catch block or a managed filter with a handler block.

    When an exception is thrown by managed code (or one is raised asynchronously, like an access violation in unsafe managed code), the CLR will begin walking the managed stack from the first managed frame it finds closest to the point of the exception and will begin looking for a managed exception handler. It is a first chance exception now.


    What is a first chance exception?

    When an application is being debugged, the debugger gets notified whenever an exception is encountered  At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception. Depending on the debugger's configuration, it will either resume the application and pass the exception on or it will leave the application suspended and enter debug mode. If the application handles the exception, it continues to run normally.


    If the application does not handle the exception, the debugger is re-notified. This is known as a "second chance" exception. The debugger again suspends the application and determines how to handle this exception. Typically, debuggers are configured to stop on second chance (unhandled) exceptions and debug mode is entered, allowing you to debug.  Or if you are running the application, a notification would show to you that an exception has happened in the application, and then the application would be closed or crashed.


    Does a first chance exception mean there is a problem in my code?

    First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled. 

    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 18, 2011 5:20 AM