474,047 Members | 35,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1635
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
8822
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 several compiler errors (missing storage-class or type specifiers) in the mentioned header file and in a header file of another dialog header file in my project. I don't expect a solution from you but can anyone give me a hint how i can find the...
12
1907
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 in the hash table). Now I have client code that looks like this: bool exception_thrown = false; try { hash_table.insert(some_value);
2
2274
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 extern and the unsafe-modifier - aren't extern functions alwys "unsafe" in the sense of "non-dotnet-function"? -- cody
2
2385
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 expected but I can not continue. I try start the execution and go back to running mode, but it always comes to the same line where the exception is first thrown.
6
6134
by: vipul DotNet | last post by:
hi, which all are the access specifiers in vb.net thank you vipul
1
4253
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.. but I've never seen a detailed descriptions of all that's possible. For example, Dim n As Integer = 65536
8
2452
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
2023
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 parts. However, this is my first time using both, and I am pretty certain that I am missing something obvious. Firstly, by debugging, I found that the first piece of data is being checked in the second case, giving me errors. I believe I may need to...
6
1976
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 <iostream> #include <string> using namespace std;
0
10550
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
12152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11607
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8706
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6665
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.