type info of exception

Discussion in 'C++' started by Old Wolf, Aug 30, 2004.

  1. Old Wolf

    Old Wolf Guest

    Is it possible to portably get the typename of an exception
    that occurred?

    I noticed when an uncaught exception occurred, GCC (3.4.1)
    displayed:

    terminate called after throwing an instance of 'std::logic_error'
    what(): basic_string::_S_construct NULL not valid

    So I tried:

    catch(std::exception &e) {
    std::cerr << "[E] Exception (" << typeid(e).name()
    << ") thrown: " << e.what() << std::endl;
    }
    but got output:
    [E] Exception (St11logic_error) thrown:
    basic_string::_S_construct NULL not valid

    ie. it said St11logic_error instead of std::logic_error. Do
    I have to try using a compiler-specific unmangling function?
     
    Old Wolf, Aug 30, 2004
    #1
    1. Advertising

  2. "Old Wolf" wrote:
    > that occurred?
    >
    > I noticed when an uncaught exception occurred, GCC (3.4.1)
    > displayed:
    >
    > terminate called after throwing an instance of 'std::logic_error'
    > what(): basic_string::_S_construct NULL not valid
    >
    > So I tried:
    >
    > catch(std::exception &e) {
    > std::cerr << "[E] Exception (" << typeid(e).name()
    > << ") thrown: " << e.what() << std::endl;
    > }
    > but got output:
    > [E] Exception (St11logic_error) thrown:
    > basic_string::_S_construct NULL not valid
    >
    > ie. it said St11logic_error instead of std::logic_error. Do
    > I have to try using a compiler-specific unmangling function?


    In the C++ standard, under 18.5.1[8], the return of
    std::type_info::name() is
    implementation-defined. This means that some compilers might chose to
    return
    "std::logic_error", some might have some specific mangled name for it
    (such as
    it is in your case) or some might even return an empty string.

    Vladimir Ciobanu
     
    Vladimir Ciobanu, Aug 30, 2004
    #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. Vasanth
    Replies:
    0
    Views:
    600
    Vasanth
    Jun 28, 2004
  2. Selen
    Replies:
    0
    Views:
    2,719
    Selen
    May 28, 2004
  3. Andrea Williams

    Clear the Render info & change to different info

    Andrea Williams, Oct 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,458
    Ken Dopierala Jr.
    Oct 27, 2004
  4. Elaine Cheong
    Replies:
    1
    Views:
    1,056
    Gordon Beaton
    Dec 9, 2006
  5. jobs
    Replies:
    1
    Views:
    1,924
    Scott Roberts
    Nov 16, 2007
Loading...

Share This Page