Exception Handling Problem

Discussion in 'ASP .Net' started by stephen, Apr 22, 2008.

  1. stephen

    stephen Guest

    Hi,

    I am a lil confused about exception handling. I have a main app and i am
    importing 2 DLL's. one of the DLL's is for connection/datasets etc and the
    other has logging errors to file.Both DLL's have try{} catch(exception
    ex){throw ex; } and i am force feeding errors so that I can catch the
    exceptions.
    I have done this:

    1. for DLL1 (Logging Errors), I am force feeding (5/0) and it throws
    "Attempted to divide by zero." exception and its propagating to the parent
    2. for DLL 2 (connnection/datasets), I am writing a non-existing STP and it
    thows "System.Data.SqlClient.SqlException Message: Could not find stored
    procedure 'stp_XXXX'. exception and its propagating to the parent
    3. the same DLL (DLL 2), I am passing a non-existent DB and it throws
    "System.NullReferenceException Message: Object reference not set to an
    instance of an object." exception and its propagating to the parent I want a
    proper error message "DB does not exist or something" but it does not.

    I have debugged the application and i observe that in the catch of DLL2, it
    does show me propermessage but when it propagates to the parent the message
    is lost. Can someone please explain what I am doing wrong?

    Thanks for your help,
    Stephen
    stephen, Apr 22, 2008
    #1
    1. Advertising

  2. stephen

    Teemu Keiski Guest

    Hi,

    throw ex;

    loses information about the stack.

    http://aspadvice.com/blogs/joteke/archive/2004/04/15/2277.aspx

    You'd better just use throw; / inner exception or follow the instructions on
    the sfollowing post

    http://weblogs.asp.net/fmarguerie/a...and-preserving-the-full-call-stack-trace.aspx

    What comes to your case, it would help to see some of the error handling
    logic. Basically, you might need to throw a custom exception on that case or
    somehow create defensive code . Seems as if passing non-existent db causes
    exception on some other object, maybe you shoukd catch
    NullReferenceException and pass it up as "DB does not exist" (the best guess
    I can make here)

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "stephen" <> wrote in message
    news:ecx%...
    >
    > Hi,
    >
    > I am a lil confused about exception handling. I have a main app and i am
    > importing 2 DLL's. one of the DLL's is for connection/datasets etc and the
    > other has logging errors to file.Both DLL's have try{} catch(exception
    > ex){throw ex; } and i am force feeding errors so that I can catch the
    > exceptions.
    > I have done this:
    >
    > 1. for DLL1 (Logging Errors), I am force feeding (5/0) and it throws
    > "Attempted to divide by zero." exception and its propagating to the parent
    > 2. for DLL 2 (connnection/datasets), I am writing a non-existing STP and
    > it thows "System.Data.SqlClient.SqlException Message: Could not find
    > stored procedure 'stp_XXXX'. exception and its propagating to the parent
    > 3. the same DLL (DLL 2), I am passing a non-existent DB and it throws
    > "System.NullReferenceException Message: Object reference not set to an
    > instance of an object." exception and its propagating to the parent I want
    > a proper error message "DB does not exist or something" but it does not.
    >
    > I have debugged the application and i observe that in the catch of DLL2,
    > it does show me propermessage but when it propagates to the parent the
    > message is lost. Can someone please explain what I am doing wrong?
    >
    > Thanks for your help,
    > Stephen
    >
    Teemu Keiski, Apr 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex

    Exception handling problem

    Alex, Jul 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    324
  2. zcraven

    exception handling problem

    zcraven, Oct 27, 2004, in forum: Java
    Replies:
    11
    Views:
    552
    zcraven
    Oct 29, 2004
  3. Replies:
    5
    Views:
    375
    Kristo
    Apr 6, 2005
  4. Peter
    Replies:
    34
    Views:
    1,915
    James Kanze
    Oct 17, 2009
  5. VSK
    Replies:
    0
    Views:
    237
Loading...

Share This Page