Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 102311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:56:20+00:00 2026-05-11T00:56:20+00:00

I found some code in a project which looks like that : int main(int

  • 0

I found some code in a project which looks like that :

int main(int argc, char *argv[]) {   // some stuff   try {   theApp.Run();  } catch (std::exception& exc) {   cerr << exc.what() << std::endl;   exit(EXIT_FAILURE);  }  return (EXIT_SUCCESS); } 

I don’t understand why the exceptions are being catched. If they weren’t, the application would simply exit and the exception would be printed.

Do you see any good reason to catch exceptions here ?


EDIT : I agree that it is good to print the exception error. However, wouldn’t it be better to rethrow the exception ? I have the feeling that we are swallowing it here…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:56:21+00:00Added an answer on May 11, 2026 at 12:56 am

    If an exception is uncaught, then the standard does not define whether the stack is unwound. So on some platforms destructors will be called, and on others the program will terminate immediately. Catching at the top level ensures that destructors are always called.

    So, if you aren’t running under the debugger, it’s probably wise to catch everything: (…) as well as std::exception. Then your application code can clean up with RAII even on a fatal exception. In many such cases you don’t actually need to clean up, since the OS will do it for you. But for instance you might prefer to disconnect cleanly from remote services where possible, and there might be resources external to the process, such as named pipes/mutexes, that you’d prefer to destroy rather than leaking.

    Rethrowing the exception in main seems to me of limited use, since you’ve already lost the context in which it was originally thrown. I suppose that trapping an uncaught exception in the debugger is noisier than just logging the fault to std::cerr, so rethrowing would be the smart move if there’s a chance of missing the logging.

    If you want the debugger to trap unexpected conditions in debug mode, which in release mode throw an exception that eventually results in an exit, then there are other ways to do that than leaving the exception uncaught so that the debugger sees it. For example, you could use assert macros. Of course, that doesn’t help with unexpected and unpredictable conditions, like hardware exceptions if you’re using SEH on .NET.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 81k
  • Answers 81k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Actually Sybase IQ is optimized for reads (think OLAP) and… May 11, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer See Quicksort on wikipedia: Typically, quicksort is significantly faster in… May 11, 2026 at 4:27 pm
  • Editorial Team
    Editorial Team added an answer Yes, there is a concurrency risk when you modify a… May 11, 2026 at 4:27 pm

Related Questions

I have a class with a static method that looks roughly like: class X
I been waiting for sometime now to bring my Asp.net Preview 4 project up
I have an existing VS 2005 Std .NET Compact Framework application that I want
One thing I've always wanted to do is develop my very own operating system

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.