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? 4 1595
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?
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" <pe*****@gmail.comwrote in message
news:e9**********************************@j20g2000 hsi.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?
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...@here.comwrote:
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...@gmail.comwrote in message
news:e9**********************************@j20g2000 hsi.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?
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@here.comwrote in message
news:uX**************@TK2MSFTNGP06.phx.gbl...
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" <pe*****@gmail.comwrote in message
news:e9**********************************@j20g2000 hsi.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?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: inquirydog |
last post by:
Hi-
One frusterating thing for me with xsl is that I don't know
how to make xslt throw some sort of exception when a value-of path
does not exist. For instance, suppose I have the following...
|
by: cody |
last post by:
I have a method that gets called if the user presses a certain button.
If the object is in a state that doesn't allow the calling of that method,
what should I do? Should I better throw an...
|
by: Arjen |
last post by:
Hi,
I'm reading the enterprise library documentation and there I see the throw
statement.
try
{
// run code
}
catch(Exception ex)
{
|
by: cat |
last post by:
I had a long and heated discussion with other developers on my team on when
it makes sense to throw an exception and when to use an alternate solution.
The .NET documentation recommends that an...
|
by: Dan |
last post by:
Hi all!
When I throw my custom Exception class the first time in my code, the
compiler takes a lot of time for find the following catch
EX:
try
Throw New MyCustomException("test")
|
by: Steve |
last post by:
I have read a couple articles online, read my Jesse Liberty book but I am
still confused as to just what the best practices are for using exceptions.
I keep changing how I'm working with them and...
|
by: Chameleon |
last post by:
Is there a possibility to create memory leak, the code below if I run
the line:
---------------------------------------------------------
MyClass cl = new MyClass();...
|
by: Fir5tSight |
last post by:
Hi,
What does "throw" do? I understand that it throws an error when
certain exceptional situation happens. My guess is that this *ignores*
the error and *continues* so that it prevents the...
|
by: Phillip Taylor |
last post by:
I don't like the way every time I write a bad sql query the debugger
takes me to the database access code. It's extremely stable and
reliable and the exceptions being thrown are because of SQL...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |