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

throw specifiers only when debugging

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
#define THROW(...) throw (__VA_ARGS__)
#else
#define THROW(...)
#endif

class Foo
{
virtual void foo() const THROW (SomeException) = 0;
{
// do something
throw SomeException("Error, Will Robinson!");
}
};

However, AFAIK C++ doesn't support variadic macros (my compiler does, as
an extension). I have methods that throw up to four different exception
types; I'd rather not have to use a different macro for every possible
number of exceptions.

Within the realm of standard C++, is there a way to selectively use or
ignore throw specifiers, as described?

Rennie
Jul 23 '05 #1
1 1608
Rennie deGraaf wrote:
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
#define THROW(...) throw (__VA_ARGS__)
#else
#define THROW(...)
#endif

class Foo
{
virtual void foo() const THROW (SomeException) = 0;
{
// do something
throw SomeException("Error, Will Robinson!");
}
};

However, AFAIK C++ doesn't support variadic macros (my compiler does, as
an extension). I have methods that throw up to four different exception
types; I'd rather not have to use a different macro for every possible
number of exceptions.

Within the realm of standard C++, is there a way to selectively use or
ignore throw specifiers, as described?

Rennie

Just wrap them up in an extra set of parens:

#define THROW(args) throw args

.... THROW((Exc1, Exc2, Exc3))

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #2

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

Similar topics

3
by: Tobias | last post by:
Hallo, I have a strange problem here: I a VC++6 project that compiles without any errors. If i now include a certain header file from my project into a header file of a certain dialog class i get...
12
by: Eric Lilja | last post by:
Hello, I'm working with a hash table that is encapsulated in a class. One of its member functions insert() throws an exception if the insertion fails (for example, if the value was already present...
2
by: codymanix | last post by:
Why can a method have the specifiers extern and override together in its signature? A extern method is a function called from a native dll. but how could i override a function??? The same is for...
2
by: kpax | last post by:
Hi, While debugging my application when an explicit exception is thrown by me (or an implicit exception is thrown internally) which is not handled anywhere in the stack, the execution breaks as...
6
by: vipul DotNet | last post by:
hi, which all are the access specifiers in vb.net thank you vipul
1
by: Chris Morse | last post by:
Hi, I've been trying to figure out where in the documentation it describes all the String.Format() formatting specifiers. So far, I've been guessing and picking up specifiers in sample code.....
8
by: Tapeesh | last post by:
I have a following piece of code. The code was compiled using g++ class A { public : virtual void fn() = 0; }; class B: virtual private A {
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...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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.