473,382 Members | 1,526 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,382 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 2232
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.