473,406 Members | 2,705 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,406 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
8 2109
"AshokG" <gw******@hotmail.comwrote in message
news:Oe**************@TK2MSFTNGP04.phx.gbl...
If you use just throw without parameter should preserve the complete stack
trace and the exception information.
[...] 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 could be that the optimizer in the compiler is inlining the function
that you are calling. Therefore, there is no longer a "line 6" -- the
function that contained line 6 has moved into line 12.
Sep 21 '07 #2
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 #3
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 #4
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 #5
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 #6

">
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 #7
"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 #8
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 #9

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

Similar topics

2
by: DazedAndConfused | last post by:
I converted a C# example of using dll crypt32 to VB .NET. The converted example fails when Encypting/Decypting. I found that if instead of defining a variable as and setting the values for...
2
by: Steve Amey | last post by:
Hi all I would like to get the values of Parameters passed to a method from a centralized exception handling routine. At the moment, the exception is passed to the handler, and I can get the...
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
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...
7
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...
7
by: PhilTheGap | last post by:
Hi, I've tried this: <asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave" OnClientClick="SaveParam (<% Util.MaxTags %>)" /> but if fails... Util is a C# class, MaxTags a...
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: 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
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.