473,654 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception Handling Problem


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.Sq lClient.SqlExce ption 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.NullRef erenceException 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
Jun 27 '08 #1
1 1150
Hi,

throw ex;

loses information about the stack.

http://aspadvice.com/blogs/joteke/ar...4/15/2277.aspx

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

http://weblogs.asp.net/fmarguerie/ar...ack-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
NullReferenceEx ception and pass it up as "DB does not exist" (the best guess
I can make here)

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

"stephen" <st********@hot mail.comwrote in message
news:ec******** ********@TK2MSF TNGP05.phx.gbl. ..
>
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.Sq lClient.SqlExce ption 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.NullRef erenceException 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

Jun 27 '08 #2

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

Similar topics

6
2123
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the exe file it doesn't catch any errors? Does anyone know what my problem might be? Regards
6
2335
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which assemblies are loaded before shutting down. In one case, some of my DB-accessing code didn't handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the...
7
5990
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
6
9958
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not everytime up through the call chain? Is there anything a caller can key off of to check to see if it should also log the exception?
44
4206
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
6
1710
by: Nick Reeves | last post by:
While developing the below code I noticed that exceptions were not working as expected. An exception is thrown inside an XML import DLL and not being caught inside the Main() code fragment, creating an unhandled exception inside "theUI". Would anybody know why this is happening? I thought the general rule for exceptions handling was the exception is passed up the stack until the application handles it or the program terminates? ...
4
5129
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xstring(1453) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
11
5573
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
41
3049
by: Stuart Golodetz | last post by:
Hi all, Just wondering whether there's any reason why exception specifications are enforced at runtime, rather than at compile-time like in Java? (This was prompted by reading an article on GOTW, incidentally.) Is there something about C++ that makes it harder/impossible to check at compile-time? Cheers, Stu
4
1777
by: DHS1 | last post by:
Hey guys. I have a lab that is due in two weeks, but I wanted to start on it now. Problem is, I'm at home during christmas break so I can't ask my professors. Here's my problem: I am given a very fragile program and I have to add the exception handling and error checking and pretty much make it uncrashable. I will show just one small step in this lab. If you can answer it, I think I'll be able to do the rest. I just need to get headed in...
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.