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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:40:21+00:00 2026-06-14T15:40:21+00:00

Possible Duplicate: What is the easiest way to make a C++ program crash? There’s

  • 0

Possible Duplicate:
What is the easiest way to make a C++ program crash?

There’s a construct I see frequently in our codebase, where the program gets into an invalid state somehow, the code will do something intentionally wrong, just to force a crash. It usually goes something like this:

if(<something is wrong>)
{
    int *ptr = NULL;
    *ptr = 0;
}

This of course causes a null reference exception and crashes the program in an unrecoverable manner. I’m just wondering if this is really the best way to do this? First of all, it doesn’t read well. Without a comment, you might not realize that the crash that occurs here is intended. Secondly, there’s pretty much no way to recover from this. It doesn’t throw an exception, so it can’t be handled by other code. It just kills the program dead with no way of backtracking. It also doesn’t give much of a clue as to why it had to crash here. And it will crash in all builds, unlike, say, an assert. (We do have a pretty robust assert system available, but it isn’t always used in cases like this.)

It’s the style we’re using all over the place, and I’m in no position to try and convince anyone otherwise. I’m just curious how common this is in the industry.

  • 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-06-14T15:40:23+00:00Added an answer on June 14, 2026 at 3:40 pm

    You should throw an exception, which is basically causing a crash deliberately and in a controlled manner. Here is an example with help from this question.

    throw string("something_went_wrong");
    

    Better yet is that the error is caught or fixed. Assert would also be a fine choice.

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

Sidebar

Related Questions

Possible Duplicate: Easiest way to get file's contents in C My program reads files
Possible Duplicate: Easiest way to find duplicate values in a JavaScript array Javascript array
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: easiest way to parse xml in python I need to parse a
Possible Duplicate: Easiest way to find duplicate values in a JavaScript array I am
Possible Duplicate: Using mercurial, what's the easiest way to commit and push a single
Possible Duplicate: What's the easiest way to install a missing Perl module? I'm attempting
Possible Duplicate: subprocess with timeout What is the easiest way to do the following
Possible Duplicate: Easiest way to sort DOM nodes? I have a list of DIVs,
Possible Duplicate: Creating a memory leak with Java What's the easiest way to cause

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.