Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:40:39+00:00 2026-06-01T17:40:39+00:00

#include iostream #include conio.h #include exception #include cstdlib using namespace std; void myunexpected ()

  • 0
#include "iostream"
#include "conio.h"
#include "exception"
#include "cstdlib"
using namespace std;

void myunexpected () 
{
    cerr << "unexpected called\n";
    throw 0;     // throws int (in exception-specification)
}

void myfunction () throw (int) 
{
    throw 'x';   // throws char (not in exception-specification)
}

int main (void) 
{
    set_unexpected (myunexpected);
   try 
   {
      myfunction();
   }
   catch (int) { cerr << "caught int\n"; }
   catch (...) { cerr << "caught other exception (non-compliant compiler?)\n"; }
   getch();
   return 0;
}

Output(When executed on Visual studio 2008):
caught other exception (non-compliant compiler?)

But, I was expecting the output to be:

unexpected called

caught int

NOTE: I executed this program on Visual Studio 2008.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:40:41+00:00Added an answer on June 1, 2026 at 5:40 pm

    Yes, as per the Standard the output should be[#1]:

    unexpected called
    caught int

    gcc gives accurate result.

    Note that, MSVC is notoriously buggy w.r.t handling exception specifications. Exception specifications are considered a failed experiment.
    AFAIK, MSVC does not implement exception specifications, except for the empty ones (throw()/nothrow)

    C++03 Standard:

    [#1] 15.5.2 The unexpected() function [except.unexpected]

    The unexpected() function shall not return, but it can throw (or re-throw) an exception. If it throws a new exception which is allowed by the exception specification which previously was violated, then the search for another handler will continue at the call of the function whose exception specification was violated….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include stdio.h #include conio.h #include <iostream> using namespace std; int main (void) { char
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include<iostream.h> #include<conio.h> using namespace std; class SpaceShip {}; class GiantSpaceShip : public SpaceShip {};
Here is my code - #include <iostream> #include <conio.h> using namespace std; class Base
I have a sample code : #include <iostream> #include <conio.h> using namespace std; int
#include <stdio.h> #include <string.h> #include <conio.h> #include <iostream> using namespace std; char a[21]; //
#include <iostream> #include <conio.h> using namespace std; class Base { int a; public: Base(const
I have written a sample program : #include<iostream> #include<set> #include<conio.h> using namespace std; int
I have the following code: #include stdafx.h #include <iostream> #include <conio.h> using namespace std;
I have 2 .cpp files a1.cpp #include <iostream> #include <conio.h> using namespace std; using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.