View Single Post
  #5 (permalink)  
Old December 8th, 2006, 03:21 PM
woodyz woodyz is offline
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can actually get the line of code that allowed the original exception to be thrown.
This is done using the inner exception.

In the code with the initial try/catch, declare an exception and place the exception caught into its inner exception member (and add whatever info you need to the new exception itself). You then throw that exception. When you display the exception somewhere in your UI code, check for the existance of an inner exception and you will find the line number in there.

Additionally you can follow a similar structure all the way up the call stack if there is some further value to adding additional info as you go. Just remember that exception handling in the .NET world should be used only for true exception handling, where in VB6 we often used error handling as part of the logic sometimes. In .NET there can be a serious performance hit as there is a great deal of overhead.

Another note: Remember that you can create your own exception classes that inherit from the base Exception class, and have a very full featured exception handling system.

Have fun.

Woody Z
http://www.learntoprogramnow.com