CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Unexpected Output

  1. #1

    Unexpected Output

    Function funExceptionHandler is not getting called though exception is thrown
    Why?

    Code:
    #include <iostream>
    #include <exception>
    using namespace std;
    
    void funExceptionHandler () {
      cerr << "unexpected handler called\n";
    }
    
    void fun () throw (int) {
      throw 1.11; // throws double (not in exception-specification)
    }
    
    int main (void) {
      set_unexpected (funExceptionHandler);
      try {
        fun();
      }
      catch (double) { cerr << "caught double\n"; }
      catch (...) { cerr << "caught other exception (non-compliant compiler?)\n"; }
      return 0;
    }

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Unexpected Output

    When I compile the example (VC2008) I get this warning.

    warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Angry Re: Unexpected Output

    Didn't I answer this yesterday?
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)