472,983 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Create Exception object

I am calling a function that requires an Exception which you normally get
from a Catch ( Catch(Exception exc)).

But I have a message I am trying to pass to this funtion, but since it
requires an Exception object, I can't just send the message.

I need to create an Exception object and make the exc.Message field equal to
my message and then pass the new object to the function.

Is there a way to do this other than forcing a Catch?

Thanks,

Tom
Jun 27 '08 #1
3 1822
tshad wrote:
I am calling a function that requires an Exception which you normally get
from a Catch ( Catch(Exception exc)).
So this function is like:
public void someFunc(Exception e)
?
But I have a message I am trying to pass to this funtion, but since it
requires an Exception object, I can't just send the message.

I need to create an Exception object and make the exc.Message field equal to
my message and then pass the new object to the function.

Is there a way to do this other than forcing a Catch?
someFunc(new Exception("Message"));

Unless I'm misunderstanding what you mean.
Some simple sample code would go a long way towards clearing up any confusion.
Chris.
Jun 27 '08 #2
As Chris indicated, Exception is a class just like any other class. Simply
create a new instance of Exception and set whatever properties you want,
then pass it into the method call as the parameter, ex:

Exception ex = new Exception();
ex.Message="blah, blah";
MyMethod (ex);

--peter
"tshad" <tf*@dslextreme.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I am calling a function that requires an Exception which you normally get
from a Catch ( Catch(Exception exc)).

But I have a message I am trying to pass to this funtion, but since it
requires an Exception object, I can't just send the message.

I need to create an Exception object and make the exc.Message field equal
to my message and then pass the new object to the function.

Is there a way to do this other than forcing a Catch?

Thanks,

Tom
Jun 27 '08 #3
On May 28, 1:16*pm, "tshad" <t...@dslextreme.comwrote:
I am calling a function that requires an Exception which you normally get
from a Catch ( Catch(Exception exc)).

But I have a message I am trying to pass to this funtion, but since it
requires an Exception object, I can't just send the message.

First of all Exception is just another class in the framework, you can
create instances of it as you please.
most probably you are calling a logging method.
You can simply say MyFunction ( new Exception("eereer"));

I advise you to do so though.
Exception has other properties (StackTrace, etc) that are usually used
to find more info about an error. You have to try your method in case
it expect those fields populated.
Also you could create an override of that method that simply receive a
String.
Jun 27 '08 #4

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

Similar topics

7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
5
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: ashishjainism | last post by:
I am unable to install my windows service and the installutil is throwing the following error: Running a transacted installation. Beginning the Install phase of the installation. See the...
1
by: mohins | last post by:
I am getting the error while I am trying to connect to Oracle with my code in ASP.NET, this code is working in another machine, but it fails in my laptop, giving the below error. Could not create...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
4
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.