473,473 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Comprehensive listing of standard C++ exceptions

I am trying to collect a comprehensive listing of standard C++
exceptions. This is what I have got so far (by going through the
standard). Kindly let me know if I missed anything.

Thanks,
Ramesh

//
// ********* Derived from std::exception *********
//
class bad_alloc; // thrown to report a failure to allocate storage

class bad_cast; // thrown to report an invalid dynamic cast
expression

class bad_typeid; // thrown to report a null pointer in a typeid
expression

class bad_exception; // thrown when an exception type doesn't match
any catch

class logic_error(const string& what_arg); // thrown to report
errors presumably
// detectable before the
program
// executes, such as
violations of
// logical preconditions or
// class invariants

class runtime_error(const string& what_arg); // thrown to report
errors presumably
// detectable only when
the program
// executes
class ios_base::failure(const string& msg); // thrown by functions
in the iostreams
// library, to report
errors detected during
// stream buffer
operations.
//
// ********* Derived from logic_error *********
//
class domain_error(const string& what_arg); // thrown to report
domain errors

class invalid_argument(const string& what_arg); // thrown to report an
invalid argument

class length_error(const string& what_arg); // thrown to report an
attempt to produce
// an object whose
length exceeds its
// maximum allowable
size

class out_of_range(const string& what_arg); // thrown to report an
argument value not in
// its expected range
//
// ********* Derived from runtime_error *********
//
class range_error(const string& what_arg); // thrown to report
range errors in
// internal
computations

class overflow_error(const string& what_arg); // thrown to report an
arithmetic overflow error

class underflow_error(const string& what_arg); // thrown to report an
arithmetic underflow error

Jan 26 '07 #1
2 1445
What does the C++ standard say about statements after throw? My
compiler (g++ version 3.3.1) does not complain even if there are
statements after an unconditional throw statement (see sample code
below)

Thanks,
Ramesh

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;

#define DEBUG
void
foo() throw (logic_error)
{
throw logic_error("Function foo called");
cerr << "Statement after throw ---- compiler should complain\n";
}
void
bar() throw (runtime_error)
{
try
{
foo();
}
catch(exception& xcptn)
{
#ifdef DEBUG
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ",
" << __LINE__ << endl;
#endif
throw runtime_error(string("Exception in function ") + __func__ +
string("()"));
cerr << "Statement after throw ---- compiler should complain\n";
}
}

main()
{
try
{
bar();
}
catch(exception& xcptn)
{
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ",
" << __LINE__ << endl;
}

return 0;
}

Feb 13 '07 #2
Generic Usenet Account wrote:
What does the C++ standard say about statements after throw?
As far as I can see: nothing.
My compiler (g++ version 3.3.1) does not complain even if there are
statements after an unconditional throw statement (see sample code
below)

Thanks,
Ramesh

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;

#define DEBUG
void
foo() throw (logic_error)
{
throw logic_error("Function foo called");
cerr << "Statement after throw ---- compiler should complain\n";
Why? As far as I can tell, there is nothing wrong with the code. It's like

if ( false ) {
cerr << "this does not print.\n";
}
}
void
bar() throw (runtime_error)
{
try
{
foo();
}
catch(exception& xcptn)
{
#ifdef DEBUG
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ",
" << __LINE__ << endl;
#endif
throw runtime_error(string("Exception in function ") + __func__ +
string("()"));
cerr << "Statement after throw ---- compiler should complain\n";
Again, there is no reason for the compiler to complain.
}
}

main()
Now, here the compiler should complain: main returns int.
{
try
{
bar();
}
catch(exception& xcptn)
{
cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ",
" << __LINE__ << endl;
}

return 0;
}
Compilers are free to issue warnings about anything that looks fishy;
however, the standard does not seem to require any diagnostics related to
unreachable code.
Best

Kai-Uwe Bux
Feb 13 '07 #3

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

Similar topics

31
by: somebody | last post by:
No, I'm not a troll, just angry. I just started learning C++, and find it extremely lacking compared to Java. For example, I had to write my own functions to do something as simple as a case...
30
by: somebody | last post by:
I'm posting a new message regarding this subject, since the one posted previously is getting rather large. I just received the June 2005 issue of Dr. Dobb's Journal, and it contains an article...
50
by: strutsng | last post by:
I want if "a C program is a standard C++ program, but not vice versa" is a correct statement? In a C++ program, we can use standard C libraries. However, we cannot use C++ libraries inside C...
0
by: Wild Wind | last post by:
Hello, I have a mixed dll which has to catch standard c++ library exceptions. Now I understand that when *any* object is thrown as an exception in managed c++, it is wrapped as a SEHException...
0
by: Epetruk | last post by:
Hello, I posted this a while back, but I have had no response yet. I have a mixed dll which has to catch standard c++ library exceptions. Now I understand that when any object is thrown as...
2
by: ngr | last post by:
I used to use the DirListox control in VB6 but this is no longer supported in VB.NET. What I want to do: I want to take a directory listing and show any subdirectories in a list. When you click...
6
by: nobrow | last post by:
I need a syntactically comprehensive test program to test a C parser on. Does anyone know where I might find a program that uses all syntactical elements of the language and combines them in...
10
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1....
4
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
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...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.