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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:00:16+00:00 2026-05-26T13:00:16+00:00

In certain cases I want my function to simply crash and my app to

  • 0

In certain cases I want my function to simply crash and my app to stop execution:

public void foo() {
    if(lifeIsWorthLiving) {
        /*code ...*/
    }
    else {
        /* log the problem, throw an exception and die */ 
    }
}

Now if I add throw Exception("lifeIsWorthLiving = false !!!"); then I need to add throws Exception to function definition and then I have to handle this everywhere I call foo(). I don’t want to do that. How can I do this?

  • 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-26T13:00:17+00:00Added an answer on May 26, 2026 at 1:00 pm

    Throw an RuntimeException or maybe Error, depending on the nature of the problem. Both doesn’t need to be declared in a throws. Last alternative is to call System#exit().

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

Sidebar

Related Questions

I have a certain function which does the following in certain cases: raise Exception,
I got a function in a certain module that I want to redefine(mock) at
I want to loop true certain elements, in this case all with the class
In certain cases - especially when an exception escapes a destructor during stack unwinding
On certain error cases ATL invokes AtlThrow() which is implemented as ATL::AtlThrowImpl() which in
In certain types of code (e.g. simulation/ games/ optimization), many physical quantities/properties are stored,
I'm using ajax calls to retrieve some HTML data. In certain cases, there are
I want to check in a script if a certain other module is already
I'm writing a simple application where I want to replace certain words with other
I use Python 2.6 and I want to replace each instance of certain leading

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.