Exception Handling in Exception Handlers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Exception Handling in Exception Handlers

Hybrid View

  1. #1
    David Williams Guest

    Exception Handling in Exception Handlers

    Sorry to do this to you folks

    I am using the Try.... Catch.... Finally structure with great success,
    however...

    How can I turn OFF the exception handling in a situation where I know that
    errors are likely to happen, and should be ignored? I.E. in a Unhanded
    Exception Handler? I code heavily to avoid ever going into this handler
    (don't we all?), but to write a completely stable service, I need to handle
    the cases where the system is already going South on me, and something so
    exceptional has happened that it is outside of my trappings. Such as the
    network going down or the database server crashing. In these cases, I want
    to turn off the exception handler so that I can get what information I can,
    and log it somewhere. (Hopefully to the event log, but I could be so dead,
    that it may be just to a file or heaven forbid, to a console screen [no
    saving that report!])

    In the past I would just do an On Error Resume Next. However, I know that
    this is something the C/C++ programmers have been handling (I hope!?!?!?!)
    for years in a structured exception handling world. So, I come to you and
    ask -- how?

    Thanks for any ideas,

    David




  2. #2
    Russell Jones Guest

    Re: Exception Handling in Exception Handlers

    One answer is to nest Try blocks--something like this. This is not tested
    code--it's only meant to give you an idea. The example below would try to
    log the error to the event log, and if that failed, would try to log the
    error to a file. If that fails, it gives up.

    You could obviously simplify this code a great deal by moving the
    file-logging code into an error trap in the event-logging code if you
    *always* wanted to log errors to a file if the event log doesn't work.

    Also, be aware that the Exceptions themselves may contain InnerExceptions
    that have more information than the exception you actually catch, so be sure
    to unwind the exceptions when you log error.

    Try
    ' do something
    Catch (ex as Exception)
    ' Try to log the error info
    Try
    logError(ex)
    Catch (LogEx as Exception)
    ' can't log, try to write a file
    Try
    writeFileError(ex)
    Catch (FileEx as Exception)
    ' can't write a file either, give up
    End Try
    End Try
    Finally
    Try
    ' cleanup here
    Catch
    ' whatever you want
    End Try
    End Try


    "David Williams" <d.w.i.l.l.i.a.m.s.@strohlsystems.com> wrote in message
    news:3cf3b0cb$1@10.1.10.29...
    > Sorry to do this to you folks
    >
    > I am using the Try.... Catch.... Finally structure with great success,
    > however...
    >
    > How can I turn OFF the exception handling in a situation where I know that
    > errors are likely to happen, and should be ignored? I.E. in a Unhanded
    > Exception Handler? I code heavily to avoid ever going into this handler
    > (don't we all?), but to write a completely stable service, I need to

    handle
    > the cases where the system is already going South on me, and something so
    > exceptional has happened that it is outside of my trappings. Such as the
    > network going down or the database server crashing. In these cases, I

    want
    > to turn off the exception handler so that I can get what information I

    can,
    > and log it somewhere. (Hopefully to the event log, but I could be so

    dead,
    > that it may be just to a file or heaven forbid, to a console screen [no
    > saving that report!])
    >
    > In the past I would just do an On Error Resume Next. However, I know that
    > this is something the C/C++ programmers have been handling (I hope!?!?!?!)
    > for years in a structured exception handling world. So, I come to you and
    > ask -- how?
    >
    > Thanks for any ideas,
    >
    > David
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center