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 / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Exception Handling Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stephen - 22 Apr 2008 23:37 GMT
Hi,

I am a lil confused about exception handling. I have a main app and i am
importing 2 DLL's. one of the DLL's is for connection/datasets etc and the
other has logging errors to file.Both DLL's have try{} catch(exception
ex){throw ex; } and i am force feeding errors so that I can catch the
exceptions.
I have done this:

1. for DLL1 (Logging Errors), I am force feeding (5/0) and it throws
"Attempted to divide by zero." exception and its propagating to the parent
2. for DLL 2 (connnection/datasets), I am writing a non-existing STP and it
thows "System.Data.SqlClient.SqlException Message: Could not find stored
procedure 'stp_XXXX'. exception and its propagating to the parent
3. the same DLL (DLL 2), I am passing a non-existent DB and it throws
"System.NullReferenceException Message: Object reference not set to an
instance of an object." exception and its propagating to the parent I want a
proper error message "DB does not exist or something" but it does not.

I have debugged the application and i observe that in the catch of DLL2, it
does show me propermessage but when it propagates to the parent the message
is lost. Can someone please explain what I am doing wrong?

Thanks for your help,
Stephen
Teemu Keiski - 23 Apr 2008 20:31 GMT
Hi,

throw ex;

loses information about the stack.

http://aspadvice.com/blogs/joteke/archive/2004/04/15/2277.aspx

You'd better just use throw; / inner exception or follow the instructions on
the sfollowing post

http://weblogs.asp.net/fmarguerie/archive/2008/01/02/rethrowing-exceptions-and-p
reserving-the-full-call-stack-trace.aspx


What comes to your case, it would help to see some of the error handling
logic. Basically, you might need to throw a custom exception on that case or
somehow create defensive code . Seems as if passing non-existent db causes
exception on some other object, maybe you shoukd catch
NullReferenceException and pass it up as "DB does not exist" (the best guess
I can make here)

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

> Hi,
>
[quoted text clipped - 21 lines]
> Thanks for your help,
> Stephen

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.