473,320 Members | 1,828 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,320 software developers and data experts.

throw ex

If I throw ex it does not give me enought informtion, if I throw
strmessage would this actually throw the message that I've created
plus the ex.message string?
catch(Exception ex)
{
strmessage = "Error Logger.Instance.LogError: " +
ex.message;
throw strmessage;
}
Nov 16 '05 #1
4 2225
Cheryl,
In addition to the other comments, I would consider using either:

throw new Exception("Error Logger.Instance.LogError: ", ex);

Or

throw new ApplicationException("Error Logger.Instance.LogError: ", ex);

Or

throw new LoggerException("Error Logger.Instance.LogError: ", ex);

Where LoggerException is a custom exception object, that you can catch
specifically or pass other information along with.

The ex parameter in the above is the Inner Exception, it allows you to
"combine" the existing exception with a new exception in a Catch block.

The following article discusses how to define an exception so it plays
nicely with the Framework (including remoting).

http://msdn.microsoft.com/library/de...rp08162001.asp

Hope this helps
Jay

"Cheryl" <ch********@aol.com> wrote in message
news:77**************************@posting.google.c om...
If I throw ex it does not give me enought informtion, if I throw
strmessage would this actually throw the message that I've created
plus the ex.message string?
catch(Exception ex)
{
strmessage = "Error Logger.Instance.LogError: " +
ex.message;
throw strmessage;
}

Nov 16 '05 #2
Cheryl,

While it is possible to throw an instance of any type in the CLR, in C#,
you are limited to throwing objects that derive from Exception. If you need
more information, you can set the Message property of the Exception class.

However, you should try and find an exception that is already defined
that matches your condition, and use that. If not, then you should derive
from the Exception (or ApplicationException) class, so that types of your
exception can be caught (this would be the indicator of the particular
condition that you have, not the Message).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cheryl" <ch********@aol.com> wrote in message
news:77**************************@posting.google.c om...
If I throw ex it does not give me enought informtion, if I throw
strmessage would this actually throw the message that I've created
plus the ex.message string?
catch(Exception ex)
{
strmessage = "Error Logger.Instance.LogError: " +
ex.message;
throw strmessage;
}

Nov 16 '05 #3
I think what you may be looking for is

throw new Exception(strmessage);

Paul

"Cheryl" <ch********@aol.com> wrote in message
news:77**************************@posting.google.c om...
If I throw ex it does not give me enought informtion, if I throw
strmessage would this actually throw the message that I've created
plus the ex.message string?
catch(Exception ex)
{
strmessage = "Error Logger.Instance.LogError: " +
ex.message;
throw strmessage;
}

Nov 16 '05 #4
Cheryl,
In addition to the other comments, I would consider using either:

throw new Exception("Error Logger.Instance.LogError: ", ex);

Or

throw new ApplicationException("Error Logger.Instance.LogError: ", ex);

Or

throw new LoggerException("Error Logger.Instance.LogError: ", ex);

Where LoggerException is a custom exception object, that you can catch
specifically or pass other information along with.

The ex parameter in the above is the Inner Exception, it allows you to
"combine" the existing exception with a new exception in a Catch block.

The following article discusses how to define an exception so it plays
nicely with the Framework (including remoting).

http://msdn.microsoft.com/library/de...rp08162001.asp

Hope this helps
Jay

"Cheryl" <ch********@aol.com> wrote in message
news:77**************************@posting.google.c om...
If I throw ex it does not give me enought informtion, if I throw
strmessage would this actually throw the message that I've created
plus the ex.message string?
catch(Exception ex)
{
strmessage = "Error Logger.Instance.LogError: " +
ex.message;
throw strmessage;
}

Nov 16 '05 #5

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

Similar topics

8
by: Christian Schuhegger | last post by:
hi, we are working on a c++ project which has a lot of thow list specifications which in the end causes a lot of problems. now i would like to remove them from the project. because the project...
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
1
by: Rennie deGraaf | last post by:
I want to use throw() specifiers on some of my methods while debugging, to help me keep track of what is going on, but remove them in release builds. My method of doing this is #ifdef DEBUG...
17
by: hplloyd | last post by:
Hi, I have a function that adds data to a database and I want to return true if the database was updated and false if there was a problem, so I am using a try... catch block... My problem is...
6
by: Arjen | last post by:
Hi, I'm reading the enterprise library documentation and there I see the throw statement. try { // run code } catch(Exception ex) {
28
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
18
by: Ranganath | last post by:
Why is throw keyword considered as an operator?
1
by: aemado | last post by:
I am trying to read in several lines, each should have exactly 5 pieces of data. I am using try/catch/throw to determine if the data is in the correct format, and trying to use iss to separate the...
4
by: Samant.Trupti | last post by:
Hi, bool CControlDrvInstance::IsRebootRequired() const throw() In this code what is throw() do? I just have slight knowledge that is a exception handler but how does it work. If I have this in...
6
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.