HighTechTalks DotNet Forums  

Throw in Catch - how can I tell

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss Throw in Catch - how can I tell in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Elmo Watson
 
Posts: n/a

Default Throw in Catch - how can I tell - 12-31-2007 , 02:36 PM






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?




Reply With Quote
  #2  
Old   
zainab
 
Posts: n/a

Default Re: Throw in Catch - how can I tell - 12-31-2007 , 02:48 PM






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:
Quote:
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?

Reply With Quote
  #3  
Old   
Elmo Watson
 
Posts: n/a

Default Re: Throw in Catch - how can I tell - 12-31-2007 , 02:53 PM



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" <pedralm (AT) gmail (DOT) com> wrote

Quote:
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?



Reply With Quote
  #4  
Old   
zainab
 
Posts: n/a

Default Re: Throw in Catch - how can I tell - 12-31-2007 , 03:06 PM



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" <s... (AT) here (DOT) com> wrote:
Quote:
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" <pedr... (AT) gmail (DOT) com> wrote in message

news:e96d27c7-406a-43b5-9a4d-0f4412bf5a93 (AT) j20g2000hsi (DOT) googlegroups.com...

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?


Reply With Quote
  #5  
Old   
Alvin Bruney [ASP.NET MVP]
 
Posts: n/a

Default Re: Throw in Catch - how can I tell - 01-03-2008 , 06:18 PM



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" <sm (AT) here (DOT) com> wrote

Quote:
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" <pedralm (AT) gmail (DOT) com> wrote in message
news:e96d27c7-406a-43b5-9a4d-0f4412bf5a93 (AT) j20g2000hsi (DOT) googlegroups.com...
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?



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.