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
RB - 21 Sep 2007 09:49 GMT
> Hi,
>
[quoted text clipped - 40 lines]
> 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.
Frans Bouma [C# MVP] - 21 Sep 2007 09:57 GMT
> Hi,
>
[quoted text clipped - 38 lines]
> 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

Signature
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------
Cor Ligthert[MVP] - 21 Sep 2007 18:52 GMT
What a dirty programming style
Cor
> Hi,
>
[quoted text clipped - 41 lines]
> Regards,
> Ashok
Göran Andersson - 21 Sep 2007 21:28 GMT
> What a dirty programming style
>
> Cor
I fail to see how that has anything at all to do with the question.

Signature
Göran Andersson
_____
http://www.guffa.com
Cor Ligthert[MVP] - 22 Sep 2007 06:19 GMT
">
> 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
Alberto Poblacion - 22 Sep 2007 09:02 GMT
> 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.
Göran Andersson - 22 Sep 2007 11:05 GMT
> ">
>> I fail to see how that has anything at all to do with the question.
[quoted text clipped - 3 lines]
>
> Cor
What code? I didn't post any code. You are not making any sense at all.

Signature
Göran Andersson
_____
http://www.guffa.com