473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Exception Processing

If Module A call Module B and Module B throw and Exception (throw new
Exception("There are problems in Module B"). If Module A wanted to throw and
exception and just pass on the text of Module B exception, would it be coded
like "throw new Exception(e.Message)"?

If Module A wanted to throw it's own exception with its own text, how would
module which called Module A find the text for both Module A and Module b?

Thanks in advance for your assistance.
Mar 14 '06 #1
1 1378
> If Module A call Module B and Module B throw and Exception (throw new
Exception("There are problems in Module B"). If Module A wanted to
throw and exception and just pass on the text of Module B exception,
would it be coded like "throw new Exception(e.Message)"?

If Module A wanted to throw it's own exception with its own text, how
would module which called Module A find the text for both Module A and
Module b?

Thanks in advance for your assistance.


Look up the constructor of the Exception class and find the overload that
has "innerException", that's the one you want.

Simply told, you can construct a new Exception object and pass it an "inner"
exception, and the code handling the exception can look at the InnerException
property to get access to it. And since each Exception object can have an
inner one, you can nest these to any level.

thus, to rethrow a new exception and preserve the old one you could use something
like this:

catch (SomeException ex)
{
throw new DifferentException("Your code screwed up", ex);
}

However, make sure there is a valid reason for doing this. If rethrowing
as a new exception gives the code that handles this new one more information
than what the previous SomeException would give, then it's a good idea, otherwise
you might just add code for no reason.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Mar 14 '06 #2

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

Similar topics

1
by: Scott J. Chlebove | last post by:
I am running a PL/SQL module in which I do the following.... BEGIN DBMS_OUTPUT.enable(1000000); -- Open file for writing. OutfileHandler1 := UTL_FILE.FOPEN(wc_file_path, wc_output_file1,...
7
by: Jacek Dziedzic | last post by:
Hi! I'm trying to make friends with exceptions. I think I'm doing well, there is one thing that bothers me, however. If an object is declared within a try block, it gets destroyed on exception,...
3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
44
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...
3
by: gemel | last post by:
I am fairly comfortable with much of the .NET Exception mechanism, but I'm a bit unsure of some areas. 1. When an exception occurs and the exception is not caught then Exception processing will...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
1
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
14
by: Rex | last post by:
Re: Looking for Tips/Writeup on overall approach to Exception Processing Hi All - I am fairly new to C# and am wondering how to best implement (overall) Exception Processing within my...
7
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.