unexpected exception

T

Teddy

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 ?
 
L

Larry I Smith

Teddy said:
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
 
R

Raymond

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.
 
R

Razzer

Teddy said:
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.
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top