Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Catch exceptions in main()? #10

Closed
elfring opened this issue Sep 7, 2016 · 5 comments
Closed

Catch exceptions in main()? #10

elfring opened this issue Sep 7, 2016 · 5 comments

Comments

@elfring
Copy link

elfring commented Sep 7, 2016

I expect that exception handling is usually supported by a C++ program. I wonder why your function "main" does not contain corresponding try and catch instructions so far.

How do you think about recommendations by Matthew Wilson in an article?

Would you like to adjust the implementation if you consider effects for uncaught/unhandled exceptions like they are described by Danny Kalev?

@utilForever
Copy link
Owner

Thanks, I'll consider your suggestion. (in milestone v0.12)

@utilForever utilForever added this to the v0.12 milestone Sep 7, 2016
@utilForever
Copy link
Owner

As you can see, it doesn't really help the debugger. If the exception is not caught, it will show you the exact location in source, where the exception is shown. So, this only makes sense in release build. I will add its code that is executed in release build only.

@elfring
Copy link
Author

elfring commented Oct 23, 2016

@utilForever
Copy link
Owner

Yes, I consider aschepler's answer.

  • Avoid std::abort.
  • Either avoid std::exit or avoid all objects with static storage duration.
  • Put a catch (...) handler in main, and make sure no allocations or exceptions happen in or after it.
  • Avoid the other programming errors that can cause std::terminate.
    • (On some implementations, functions compiled with a C compiler act like they have C++'s empty throw() specification, meaning that exceptions cannot be thrown "past" them even though they have no destructors to be called.)

@utilForever
Copy link
Owner

utilForever commented Oct 24, 2016

Maybe, I guess...

int main()
{
#ifndef _DEBUG
    try
    {
#endif
        ...
#ifndef _DEBUG
    }
    catch (...)
    {
        ...
    }
#endif
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants