473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Throw without parameter...


Hi,

If you use just throw without parameter should preserve the complete stack
trace and the exception information.

for example:

1. private void Bar()
2. {
3. try
4. {
5. string s = null;
6. if (s.Length == 0)
7. return;
8. }
9. catch
10. {
11. // do some processing...
12. throw;
13. }
14. }
15.
16.private void Foo()
17.{
18. try
19. {
20. Bar();
21. }
22. catch (Exception ex)
23. {
24. // do some processing...
25. Console.WriteLine(ex.ToString())
26. }
27.}

In the above code it should show error line nos 6, 12 and 20 in the stack
trace. But now in newer versions it is just showing the line nos. 12 and 20.

It seems this functionality is removed or a bug in newer versions. It's no
longer preserving the stack trace info. I saw this In .NET l.0 framework
(VS.NET 2002).
Regards,
Ashok
Sep 21 '07 #1
7 1503
RB
AshokG wrote:
Hi,

If you use just throw without parameter should preserve the complete stack
trace and the exception information.

for example:

1. private void Bar()
2. {
3. try
4. {
5. string s = null;
6. if (s.Length == 0)
7. return;
8. }
9. catch
10. {
11. // do some processing...
12. throw;
13. }
14. }
15.
16.private void Foo()
17.{
18. try
19. {
20. Bar();
21. }
22. catch (Exception ex)
23. {
24. // do some processing...
25. Console.WriteLine(ex.ToString())
26. }
27.}

In the above code it should show error line nos 6, 12 and 20 in the stack
trace. But now in newer versions it is just showing the line nos. 12 and 20.

It seems this functionality is removed or a bug in newer versions. It's no
longer preserving the stack trace info. I saw this In .NET l.0 framework
(VS.NET 2002).
Regards,
Ashok

Java would certainly preserve the stack trace, but I've never known .NET
to do that.

In .NET I tend to use nested exceptions for this functionality as it
will print out the stack trace of the caught exception, and all nested
exceptions.

So, your line 9 -13 becomes:

catch (Exception ex)
{
throw new Exception("I'm nesting an exception", ex)
}

Cheers,

RB.
Sep 21 '07 #2
AshokG wrote:
>
Hi,

If you use just throw without parameter should preserve the complete
stack trace and the exception information.

for example:

1. private void Bar()
2. {
3. try
4. {
5. string s = null;
6. if (s.Length == 0)
7. return;
8. }
9. catch
10. {
11. // do some processing...
12. throw;
13. }
14. }
15.
16.private void Foo()
17.{
18. try
19. {
20. Bar();
21. }
22. catch (Exception ex)
23. {
24. // do some processing...
25. Console.WriteLine(ex.ToString())
26. }
27.}

In the above code it should show error line nos 6, 12 and 20 in the
stack trace. But now in newer versions it is just showing the line
nos. 12 and 20.

It seems this functionality is removed or a bug in newer versions.
It's no longer preserving the stack trace info. I saw this In .NET
l.0 framework (VS.NET 2002).
Isn't there an inner exception in 'ex' in Foo ?

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Sep 21 '07 #3
What a dirty programming style

Cor
"AshokG" <gw******@hotmail.comschreef in bericht
news:Oe**************@TK2MSFTNGP04.phx.gbl...
>
Hi,

If you use just throw without parameter should preserve the complete stack
trace and the exception information.

for example:

1. private void Bar()
2. {
3. try
4. {
5. string s = null;
6. if (s.Length == 0)
7. return;
8. }
9. catch
10. {
11. // do some processing...
12. throw;
13. }
14. }
15.
16.private void Foo()
17.{
18. try
19. {
20. Bar();
21. }
22. catch (Exception ex)
23. {
24. // do some processing...
25. Console.WriteLine(ex.ToString())
26. }
27.}

In the above code it should show error line nos 6, 12 and 20 in the stack
trace. But now in newer versions it is just showing the line nos. 12 and
20.

It seems this functionality is removed or a bug in newer versions. It's no
longer preserving the stack trace info. I saw this In .NET l.0 framework
(VS.NET 2002).
Regards,
Ashok

Sep 21 '07 #4
Cor Ligthert[MVP] wrote:
What a dirty programming style

Cor
I fail to see how that has anything at all to do with the question.

--
Göran Andersson
_____
http://www.guffa.com
Sep 21 '07 #5

">
I fail to see how that has anything at all to do with the question.
I fail to see why you are sending this message, the code does not even
compile in VB.Net.

Cor

Sep 22 '07 #6
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:15**********************************@microsof t.com...
I fail to see why you are sending this message, the code does not even
compile in VB.Net.
That's one of the reasons why cross-posting to multiple groups is
discouraged. The original poster sent the message (which contained some code
in C#) to multiple groups, including the VB group, where of course the code
won't even compile.

Sep 22 '07 #7
Cor Ligthert[MVP] wrote:
>
">
>I fail to see how that has anything at all to do with the question.
I fail to see why you are sending this message, the code does not even
compile in VB.Net.

Cor
What code? I didn't post any code. You are not making any sense at all.

--
Göran Andersson
_____
http://www.guffa.com
Sep 22 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
4
by: Cheryl | last post by:
If I throw ex it does not give me enought informtion, if I throw strmessage would this actually throw the message that I've created plus the ex.message string? catch(Exception ex) {...
17
by: Phlip | last post by:
C++ers: I have this friend who thinks C++ cannot throw from a destructor. I think throwing from a destructor is bad Karma, and should be designed around, but that C++ cannot strictly prevent...
24
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();...
7
by: dick | last post by:
in the "try{throw}catch" structure, how the C++ code return the "type" thrown by a function?
4
by: Fred | last post by:
Is it possible to use throw in javascript without try..catch? As far as I know, you must call it from within a try..catch block, or the function that calls throw must itself be called from within...
4
by: Oscar | last post by:
Hi, I got a webservie that supply users with binary files based on a parameter id. The method is void and I stream the file by: HttpContext.Current.Response.ContentType = "application/xxx";...
8
by: AshokG | last post by:
Hi, If you use just throw without parameter should preserve the complete stack trace and the exception information. for example: 1. private void Bar() 2. { 3. try
6
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.