• Advertisement
Sign in to follow this  

exception not being caught in catch block.

This topic is 4168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, ok, so i have a dll and an exe project. I'm calling the function cw::x() from the dll. cw::x() in turn calls function cw::y() which is also part of the library. and finally cw::y() throws a cw::exception object. cw::exception actually inherits from std::exception. note: cw is a namespace, not an object. in the exe, from main i have this:
main() {
  try {
    cw::x();
  }
  catch( std::exception& e ) {
    std::cout << e.what() << std::endl;
  }
}
But whenever i ran the application, i get an unhandled exception message from windows. you know that "this application has requested the runtime to close it in a weird way" message in my console window. am i missing something?

Share this post


Link to post
Share on other sites
Advertisement
Are you sure that the exception is thrown in main (could be upon construction/destruction of global/static objects)? Are you sure the exception thrown is inherited from std::exception? Try placing a catch(...) in main. What IDE do you use? Some IDEs allow you to break into the code as soon as the exception is thrown. What happens if cw::x and cw::y is moved to the exe? Does the same still happen?

Share this post


Link to post
Share on other sites
woopsy.... i was inheriting privately from std::exception. Everything worked fine after i changed to

class cw::exception : public std::exception {};

Sorry :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement