Throw in Catch - how can I tell

Discussion in 'ASP .Net' started by Elmo Watson, Dec 31, 2007.

  1. Elmo Watson

    Elmo Watson Guest

    I've got one main method, with a Try Catch block. In that, I catch the error
    and put it on a label.

    However, inside the Try portion, I also run another method. I have a
    Try/Catch block there, also, except I just have 'Throw' in the Catch
    portion.

    How can I send something from this 'internal' method, to the 'outer' method,
    so I can see where the actual failure is coming from?
     
    Elmo Watson, Dec 31, 2007
    #1
    1. Advertising

  2. Elmo Watson

    zainab Guest

    You can remove the try/catch block from the "inside" method altogether
    and have the "outside" catch actually catch it.

    If you want to keep the try/catch inside, you can have something like:

    catch (Exception ex)
    {
    throw ex;
    }

    instead of just "throw" and send the exception "up", to be catched by
    the catch block there.

    Elmo Watson escreveu:
    > I've got one main method, with a Try Catch block. In that, I catch the error
    > and put it on a label.
    >
    > However, inside the Try portion, I also run another method. I have a
    > Try/Catch block there, also, except I just have 'Throw' in the Catch
    > portion.
    >
    > How can I send something from this 'internal' method, to the 'outer' method,
    > so I can see where the actual failure is coming from?
     
    zainab, Dec 31, 2007
    #2
    1. Advertising

  3. Elmo Watson

    Elmo Watson Guest

    What's the difference between 'throw' and 'throw ex'?

    With the 'Throw', it does get sent up to the main method - but there is
    nothing in the error message, that distinctly identifies it as being from
    the 'inner' method -
    What I'd like to know is how to Add something to the error message, so when
    the error happens, it's easily identified as being from the 'inner' method.


    "zainab" <> wrote in message
    news:...
    > You can remove the try/catch block from the "inside" method altogether
    > and have the "outside" catch actually catch it.
    >
    > If you want to keep the try/catch inside, you can have something like:
    >
    > catch (Exception ex)
    > {
    > throw ex;
    > }
    >
    > instead of just "throw" and send the exception "up", to be catched by
    > the catch block there.
    >
    > Elmo Watson escreveu:
    >> I've got one main method, with a Try Catch block. In that, I catch the
    >> error
    >> and put it on a label.
    >>
    >> However, inside the Try portion, I also run another method. I have a
    >> Try/Catch block there, also, except I just have 'Throw' in the Catch
    >> portion.
    >>
    >> How can I send something from this 'internal' method, to the 'outer'
    >> method,
    >> so I can see where the actual failure is coming from?
     
    Elmo Watson, Dec 31, 2007
    #3
  4. Elmo Watson

    zainab Guest

    You can either look up in the "upper" catch's exceptions and read the
    name of the method where the exception was thrown to identify it
    (TargetSite.Name, i think) or concatenate something to the exception
    string in the "inside" catch.

    maybe somethign like:

    catch (Exception ex)
    {
    throw new Exception("Inner:" + ex);
    }

    ?
    I'm not sure if this is what you want...

    happy new year :)

    On 31 Dez, 19:53, "Elmo Watson" <> wrote:
    > What's the difference between 'throw' and 'throw ex'?
    >
    > With the 'Throw', it does get sent up to the main method - but there is
    > nothing in the error message, that distinctly identifies it as being from
    > the 'inner' method -
    > What I'd like to know is how to Add something to the error message, so when
    > the error happens, it's easily identified as being from the 'inner' method..
    >
    > "zainab" <> wrote in message
    >
    > news:...
    >
    > > You can remove the try/catch block from the "inside" method altogether
    > > and have the "outside" catch actually catch it.

    >
    > > If you want to keep the try/catch inside, you can have something like:

    >
    > > catch (Exception ex)
    > > {
    > >                throw ex;
    > > }

    >
    > > instead of just "throw" and send the exception "up", to be catched by
    > > the catch block there.

    >
    > > Elmo Watson escreveu:
    > >> I've got one main method, with a Try Catch block. In that, I catch the
    > >> error
    > >> and put it on a label.

    >
    > >> However, inside the Try portion, I also run another method. I have a
    > >> Try/Catch block there, also, except I just have 'Throw' in the Catch
    > >> portion.

    >
    > >> How can I send something from this 'internal' method, to the 'outer'
    > >> method,
    > >> so I can see where the actual failure is coming from?
     
    zainab, Dec 31, 2007
    #4
  5. If you are having this much problems separating the reporting of the error,
    maybe you should separate the two pieces of code into their own try/catch
    blocks. It doesn't hurt performance but actually improves your reporting
    scenario.

    --
    --
    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    The O.W.C. Black Book, 2nd Edition
    Exclusively on www.lulu.com/owc $19.99


    "Elmo Watson" <> wrote in message
    news:uXIm#a#...
    > What's the difference between 'throw' and 'throw ex'?
    >
    > With the 'Throw', it does get sent up to the main method - but there is
    > nothing in the error message, that distinctly identifies it as being from
    > the 'inner' method -
    > What I'd like to know is how to Add something to the error message, so
    > when the error happens, it's easily identified as being from the 'inner'
    > method.
    >
    >
    > "zainab" <> wrote in message
    > news:...
    >> You can remove the try/catch block from the "inside" method altogether
    >> and have the "outside" catch actually catch it.
    >>
    >> If you want to keep the try/catch inside, you can have something like:
    >>
    >> catch (Exception ex)
    >> {
    >> throw ex;
    >> }
    >>
    >> instead of just "throw" and send the exception "up", to be catched by
    >> the catch block there.
    >>
    >> Elmo Watson escreveu:
    >>> I've got one main method, with a Try Catch block. In that, I catch the
    >>> error
    >>> and put it on a label.
    >>>
    >>> However, inside the Try portion, I also run another method. I have a
    >>> Try/Catch block there, also, except I just have 'Throw' in the Catch
    >>> portion.
    >>>
    >>> How can I send something from this 'internal' method, to the 'outer'
    >>> method,
    >>> so I can see where the actual failure is coming from?

    >
    >
     
    Alvin Bruney [ASP.NET MVP], Jan 3, 2008
    #5
    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. Kerri
    Replies:
    2
    Views:
    13,122
    Kevin Spencer
    Oct 27, 2003
  2. Jon Maz
    Replies:
    7
    Views:
    4,349
    Jon Maz
    Oct 25, 2004
  3. Replies:
    15
    Views:
    7,772
    Roedy Green
    Sep 8, 2005
  4. yogesh
    Replies:
    1
    Views:
    399
    Victor Bazarov
    Mar 14, 2007
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    351
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page