473,386 Members | 1,610 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,386 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 2234
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.