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

  • SEARCH
  • Home
  • 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 3617012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:34:11+00:00 2026-05-18T22:34:11+00:00

I am reading about exception handling. I got some information about what exception handling

  • 0

I am reading about exception handling. I got some information about what exception handling is, but I have a few questions:

  1. When to throw an exception?
  2. Instead of throwing an exception, can we use a return value to indicate the error?
  3. If I protect all my functions by try-catch blocks, won’t it reduce the performance?
  4. When to use exception handling?
  5. I saw a project where each and every function in that project contained a try-catch block (i.e. code inside the entire function is surrounded by try-catch block). Is this a good practice?
  6. What is the difference between try-catch and __try __except?
  • 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. Editorial Team
    Editorial Team
    2026-05-18T22:34:12+00:00Added an answer on May 18, 2026 at 10:34 pm

    Here’s quite comprehensive guide on exceptions that I think is a Must Read:

    Exceptions and error handling – C++ FAQ or C++ FAQ lite

    As a general rule of thumb, throw an exception when your program can identify an external problem that prevents execution. If you receive data from the server and that data is invalid, throw an exception. Out of disk space? Throw an exception. Cosmic rays prevent you from querying the database? Throw an exception. But if you get some invalid data from inside your very own program – don’t throw an exception. If your problem comes from your own bad code, it’s better to use ASSERTs to guard against it. Exception handling is needed to identify problems that program cannot handle and tell them about the user, because user can handle them. But bugs in your program are not something the user can handle, so program crashing will tell not much less than “Value of answer_to_life_and_universe_and_everything is not 42! This should never happen!!!!11” exception.

    Catch an exception where you can do something useful with it, like, display a message box. I prefer to catch an exception once inside a function that somehow handles user input. For example, user presses button “Annihilate all hunams”, and inside annihilateAllHunamsClicked() function there’s a try…catch block to say “I can’t”. Even though annihilation of hunamkind is a complex operation that requires calling dozens and dozens of functions, there is only one try…catch, because for a user it’s an atomic operation – one button click. Exception checks in every function are redundant and ugly.

    Also, I can’t recommend enough getting familiar with RAII – that is, to make sure that all data that is initialized is destroyed automatically. And that can be achieved by initializing as much as possible on stack, and when you need to initialize something on heap, use some kind of smart pointer. Everything initialized on the stack will be destroyed automatically when an exception is thrown. If you use C-style dumb pointers, you risk memory leak when an exception is thrown, because there is noone to clean them up upon exception (sure, you can use C-style pointers as members of your class, but make sure they are taken care of in destructor).

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

Sidebar

Related Questions

I have been reading about exception handling on the Apple developer docs , but
I was reading some things about exception handling in Java, to be able to
I have been reading other questions and answers around this but I am not
When reading about SQL Injection and XSS i was wondering if you guys have
I have been reading about the differences between Table Variables and Temp Tables and
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
I am reading about COFF file formats, which is commonly used to create an
I was reading about output buffering in JavaScript here , and was trying to
I keep reading about C99 and C++11 and all these totally sweet things that
I've been reading about the new developer-only RC0 for Silverlight, and the fact that

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.