Thread: set_unexpected with arguments

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    219

    set_unexpected with arguments

    The signature of set_unexpected handler doesn't take any argument.

    But I want to print which Exception hass been occured along with the error message from the set_unexpected callback function !!

    So How can it be made possible.
    I dont want to patch GCC's files.

    It Can also be done If set_unexpected(std::exception) overload exists.
    or there exists some way to get the last raised uncaught exception somehow.
    or may be some other way too..

  2. #2
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    I've got an Idea
    Put main in a try catch block that catches all kinda exception either by ... or by std::exception

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by noobcpp View Post
    I've got an Idea
    Put main in a try catch block that catches all kinda exception either by ... or by std::exception
    All executable code must be _within_ main, including try/catch blocks...
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    There is function level try...catch which can also be around main.

    It probably won't help, because if an unexpected exception is thrown (one that violates the exception specification) it won't reach the catch handler anyway.

    I probably simply wouldn't use the throw specification if I don't know what exception might be thrown from the function.

    ------------

    If either me or the OP misunderstand what unexpected is about, then yes catch all std::exception&'s in an outermost scope allows you to print what(), and catching ... just tells you that there was an exception.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can #include <cxxabi.h> or something like that and call __cxa_get_exception_type() or something like that to get the type_info structure of the current exception. Then you can use this structure to get additional information - the same header contains information about how to do that.

    The above is specific to compilers that implement the IA-64 C++ ABI: all compilers that run on Intel IA-64, as well as GCC and a few others everywhere.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Here In My Application the main job is done through an exec() method which is being called by main()
    So I just put a try catch block around that exec() one

    and It is workinf nicely.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What anon said is important, though. The unexpected handler is for exceptions that violated an exception specification. The handler you were looking for is the uncaught handler.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 02:11 PM