468,771 Members | 1,771 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

unexpected exception

Hello all

According to "Think in C++ Volume2", the code below should run
smoothly:
#include <iostream>
#include <exception>
using namespace std;

class ex {
};

void func() throw(ex) {
throw 10;
}

void my_unexpected() {
cout << "unexpected exception" << endl; // this never shows up on my
VC compilers
exit(0);
}

int main()
{
set_unexpected(my_unexpected);

try {
func();
}
catch(ex) {
cout << "ex caught" << endl;
}

return 0;
}
But on my VC2003 and VC2005 BETA2, there will be a compiling warning
and a runtime error.
VC doesn't support unexpected exception ?
or something else ?

Jul 23 '05 #1
3 2573
Teddy wrote:
Hello all

According to "Think in C++ Volume2", the code below should run
smoothly:
#include <iostream>
#include <exception>
using namespace std;

class ex {
};

void func() throw(ex) {
throw 10;
}

void my_unexpected() {
cout << "unexpected exception" << endl; // this never shows up on my
VC compilers
exit(0);
}

int main()
{
set_unexpected(my_unexpected);

try {
func();
}
catch(ex) {
cout << "ex caught" << endl;
}

return 0;
}
But on my VC2003 and VC2005 BETA2, there will be a compiling warning
and a runtime error.
VC doesn't support unexpected exception ?
or something else ?


The code works fine for me (SuSE Linux Pro v9.2,
g++ v3.3.4). It produces the expected output:

"unexpected exception"

So it must be a VC problem. Try checking
with a VC-specific forum.

Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #2
Hello Teddy:

I have compile and run this program using MinGW g++.
The result is "unexpected exception". So g++ support the unexpected
exception.

The following his the Version Information of my compiler.

--------------------------------------------------------
g++ (GCC) 3.4.2 (mingw-special)
Copyright (C) 2004 Free Software Foundation, Inc.
--------------------------------------------------------

Jul 23 '05 #3


Teddy wrote:
Hello all

According to "Think in C++ Volume2", the code below should run
smoothly:
#include <iostream>
#include <exception>
using namespace std;

class ex {
};

void func() throw(ex) {
throw 10;
}

void my_unexpected() {
cout << "unexpected exception" << endl; // this never shows up on my
VC compilers
exit(0);
}

int main()
{
set_unexpected(my_unexpected);

try {
func();
}
catch(ex) {
cout << "ex caught" << endl;
}

return 0;
}
But on my VC2003 and VC2005 BETA2, there will be a compiling warning
and a runtime error.
VC doesn't support unexpected exception ?
or something else ?


The Microsoft compilers ignore the exception specification that you
specified on your function. It is a compiler limitiation, so you will
not get the expected (conforming) results.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ken | last post: by
2 posts views Thread by Attila Feher | last post: by
14 posts views Thread by George2 | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.