Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > unexpected exception

Reply
Thread Tools

unexpected exception

 
 
Teddy
Guest
Posts: n/a
 
      05-25-2005
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 ?

 
Reply With Quote
 
 
 
 
Larry I Smith
Guest
Posts: n/a
 
      05-25-2005
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.
 
Reply With Quote
 
 
 
 
Raymond
Guest
Posts: n/a
 
      05-25-2005
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.
--------------------------------------------------------

 
Reply With Quote
 
Razzer
Guest
Posts: n/a
 
      05-25-2005


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Unexpected exception... Ned Cisco 2 10-27-2005 10:04 PM
Unexpected exception Roberto Patrunen Cisco 8 10-15-2004 02:02 AM
unexpected exception in jni native method nicolas edel Java 5 07-31-2003 10:30 AM



Advertisments