472,951 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

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 2805
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: commosoft | last post by:
Hi all, have you ever seen this kind of error? This happens only on certain types of Sun machines (SunFire280R) but not on other types of machines (SunBlade2000 or SunBlade100). I tried to...
0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
4
by: | last post by:
Some time ago I installed VC# 2003, made a small generic project, compile with the allow unsafe flag and I get the error below: "error CS1577: Assembly generation failed -- Unexpected exception...
1
by: Ken | last post by:
Any thoughts on making explicit calls to unexpected()? My sense is that this function is really intended to be invoked automatically as part of exception handling. Are there times when explicit...
2
by: Attila Feher | last post by:
Hi all, I have not done much work around exceptions; and even when I do I avoid exception specifications. But now I have to teach people about these language facilities, so I am trying them out...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
2
by: bb | last post by:
Hi, I am using gcc v4.0.2 on fedora core 4 (2.6.16). Any reason why the handler set thru' set_unexpected() never gets called in the following code? --------- Code ------------- #include...
3
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
14
by: George2 | last post by:
Hello everyone, This question is about when it is allowed to call throw to re-throw exception -- make the exception re-throw. I can only think of two situations, 1. in catch block of an...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.