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 692401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:50+00:00 2026-05-14T02:38:50+00:00

Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider

  • 0

Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider this example:

Class User {

  public function User(user){
  
    // Query database for user data

    if(!user) throw new ExistenceException('User not found');

  }

}

I’d argue that it makes as much sense to simply return false (or set all user data to false in this case), rather than throwing an exception.

Which do you prefer?

  • 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-14T02:38:50+00:00Added an answer on May 14, 2026 at 2:38 am

    Throw exception in exceptional circumstances.

    If the condition is something you expect in the normal run of the program, check for it and report an error. Reserve exceptions for things that should never happen, or as an indication to other programmers that something unrecoverable has occurred.

    In your case, returning false makes more sense (or perhaps use a null object as a return value).

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

Sidebar

Related Questions

I just joined this wonderful community, but it is with regret that I admit
Java's checked exceptions sometimes force you to catch a checked exception that you believe
How can I handle exceptions in a linq query? For example if I have
I am testing for Exceptions using unittest, for example: self.assertRaises(UnrecognizedAirportError, func, arg1, arg2) and
I know that exceptions have a performance penalty, and that it's generally more efficient
#exceptions is a html table. I try to run the code below, but it
Throwing exceptions often follows the following pattern: if(condition) { throw exception; } you check
Hey guys I'm getting three things right now that I'm trying to take care
Exceptions cause Node.js servers to crash. The common wisdom is that one needs to
Exceptions can have different degrees of impact on a program. For example a program

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.