Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Throw without parameter...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AshokG - 21 Sep 2007 08:06 GMT
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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.