locked
ostringstream throwing unhandled exception RRS feed

  • Question

  • Hi,

    i have a piece of code in vc++ which throws unhandled exception

    try

    {

    double f_dblFloatVal = 1.6471107532125e+113;

    std::ostringstream strs;

    strs.setf(ios_base::fixed);
    strs << f_dblFloatVal;   // throws unhandled exception

    }

    catch(...)

    {

    return;

    }

    Can any body tell whats going wrong

    Tuesday, December 20, 2011 4:05 PM

Answers

  • >i have a piece of code in vc++ which throws unhandled
    >exception

    What *kind* of exception?

    Which version of VC++ are you using?

    Is this a Debug or Release build?

    Your snippet built with VC++ 2008 Express gives no
    exception. Adding this:

    std::cout << strs.str() << std::endl;

    displays this:

    16471107532124998000000000000000000000000
    00000000000000000000000000000000000000000
    00000000000000000000000000000000.000000

    Tip: For proper viewing of the contents of an ostringstream
    in the VC++ debugger, add a nul-terminator:

    strs << std::ends;

    - Wayne
    • Proposed as answer by Helen Zhao Monday, December 26, 2011 5:03 AM
    • Marked as answer by Helen Zhao Wednesday, December 28, 2011 2:04 AM
    Tuesday, December 20, 2011 11:57 PM

All replies

  • You do realise that you're asking for a 114-digit long representation of that value, don't you?

    catch(...) only catches C++ exceptions; the chances are that you're hitting a hardware exception.  These can be caught using Structured Exception Handling, although it's a bit tricky to achieve in a C++ program, because the compiler won't allow you to use C++ try and SEH __try in the same compilation unit.


    Answering policy: see profile.
    • Edited by David Boyce UK Tuesday, December 20, 2011 4:38 PM
    • Proposed as answer by Helen Zhao Wednesday, December 28, 2011 2:05 AM
    Tuesday, December 20, 2011 4:37 PM
  • >i have a piece of code in vc++ which throws unhandled
    >exception

    What *kind* of exception?

    Which version of VC++ are you using?

    Is this a Debug or Release build?

    Your snippet built with VC++ 2008 Express gives no
    exception. Adding this:

    std::cout << strs.str() << std::endl;

    displays this:

    16471107532124998000000000000000000000000
    00000000000000000000000000000000000000000
    00000000000000000000000000000000.000000

    Tip: For proper viewing of the contents of an ostringstream
    in the VC++ debugger, add a nul-terminator:

    strs << std::ends;

    - Wayne
    • Proposed as answer by Helen Zhao Monday, December 26, 2011 5:03 AM
    • Marked as answer by Helen Zhao Wednesday, December 28, 2011 2:04 AM
    Tuesday, December 20, 2011 11:57 PM
  • Hi pprithvi,

    I have tested your codes on my PC with VS2010 Ultimate installed. I have not seen any errors or exceptions when compiling and linking. And I see the same result on console window with WayneAKing.

    Now I’d like to mark answers for this thread, if you have any questions, you can post back and unmark them. We’ll continue working with you on this issue.

    Thanks for your understanding and active participation in the MSDN Forum.

    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, December 28, 2011 2:04 AM