throw specifiers only when debugging

R

Rennie deGraaf

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
 
A

Artie Gold

Rennie said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top