Nested exception throwing

Discussion in 'C++' started by usenet@sta.samsung.com, May 19, 2007.

  1. Guest

    I wrote some sample code (see below) for nested exception throwing
    i.e. my catch blocks are throwing exceptions of their own (for
    simplicity I used standard exceptions). I am getting some extraneous
    characters (St9) in my final output. Can anyone kindly help me
    interpret that please?

    Thanks,
    Ramesh



    Here's my output:
    Exception bad_alloc in function func_level3()
    Exception: Exception: Exception: St9bad_alloc in function
    func_level2() in function func_level1() at xcptn-test.cpp,74



    Here's my sample code:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <stdexcept>
    // Standard exceptions:-
    // bad_alloc, bad_cast, bad_typeid,
    bad_exception,
    // logic_error, runtime_error,
    ios_base::failure
    // domain_error, invalid_argument,
    length_error
    // out_of_range, range_error,
    overflow_error,
    // underflow_error

    using namespace std;


    //////////////////////////////////////////////////////////////////
    //
    //////////////////////////////////////////////////////////////////
    void
    func_level3() throw (bad_alloc)
    {
    cerr << "Exception bad_alloc in function " << __func__ << "()\n";
    throw bad_alloc();
    }


    //////////////////////////////////////////////////////////////////
    //
    //////////////////////////////////////////////////////////////////
    void
    func_level2() throw (runtime_error)
    {
    try
    {
    func_level3();
    }
    catch(exception& xcptn)
    {
    ostringstream oss;
    oss << "Exception: " << xcptn.what() << " in function " <<
    __func__ << "()";
    throw runtime_error(oss.str());
    }
    }

    //////////////////////////////////////////////////////////////////
    //
    //////////////////////////////////////////////////////////////////
    void
    func_level1() throw (domain_error)
    {
    try
    {
    func_level2();
    }
    catch(exception& xcptn)
    {
    ostringstream oss;
    oss << "Exception: " << xcptn.what() << " in function " <<
    __func__ << "()";
    throw domain_error(oss.str());
    }
    }


    //////////////////////////////////////////////////////////////////
    //
    //////////////////////////////////////////////////////////////////
    main()
    {
    try
    {
    func_level1();
    }
    catch(exception& xcptn)
    {
    cerr << "Exception: " << xcptn.what() << " at " << __FILE__ << ","
    << __LINE__ << endl;
    }
    }
    , May 19, 2007
    #1
    1. Advertising

  2. BobR Guest

    <> wrote in message ...
    > I wrote some sample code (see below) for nested exception throwing
    > i.e. my catch blocks are throwing exceptions of their own (for
    > simplicity I used standard exceptions). I am getting some extraneous
    > characters (St9) in my final output. Can anyone kindly help me
    > interpret that please?
    > Thanks, Ramesh
    >
    > Here's my output:
    > Exception bad_alloc in function func_level3()
    > Exception: Exception: Exception: St9bad_alloc in function
    > func_level2() in function func_level1() at xcptn-test.cpp,74


    [ this is only my own theory/logic (i have not read-up on it) ]

    GCC(g++) decorates the exception name. I believe that the 'St' stands for
    'standard'(or 'standard template'). Someone else thought the '9' is the
    number of characters that follow, and that seem to hold true for all I've
    seen (in GCC).

    What compiler are you using?
    ( Even though we don't discuss compilers here, it's sometimes helpful to
    know which one gave the output.).

    If you are deriving from std::exception, see my last post in this thread for
    more:
    Newsgroups: comp.lang.c++
    Sent: Wednesday, May 16, 2007
    Subject: exception and polymorphism problem

    --
    Bob R
    POVrookie
    BobR, May 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KJ
    Replies:
    5
    Views:
    376
    John Saunders
    Jul 25, 2003
  2. VincentWong
    Replies:
    1
    Views:
    551
    VincentWong
    Dec 29, 2003
  3. =?Utf-8?B?VGVycnk=?=
    Replies:
    4
    Views:
    5,989
    =?Utf-8?B?VGVycnk=?=
    Jan 13, 2005
  4. =?Utf-8?B?R2xlbm4gVmVuemtl?=

    System.IO.Directoryinfo throwing exception

    =?Utf-8?B?R2xlbm4gVmVuemtl?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,690
    John Timney \(ASP.NET MVP\)
    Jul 25, 2005
  5. =?Utf-8?B?RXVzdGljZSBTY3J1YmI=?=

    Insert.aspx throwing exception

    =?Utf-8?B?RXVzdGljZSBTY3J1YmI=?=, Sep 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    573
    =?Utf-8?B?RXVzdGljZSBTY3J1YmI=?=
    Sep 23, 2005
Loading...

Share This Page