How do I specify a message when calling abort() in C?

Viewed 155

I tried to open Minecraft in a really old version of MacOS. Every time it opens it says Minecraft Launcher quit unexpectedly along with a custom message at the bottom.

Exception Type: SIGABRT  
Exception Code: 0x000000000000 0x000000000000  
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:  
abort() called  
Minecraft requires at least MacOS 10.9, and trying to run on 10.8.5

How can I do the same thing in my code? If I call abort(), how can I specify a reason to display under Application Specific Information in the Application Quit Unexpectedly window?

2 Answers

There is no way to specify an error message (or any message) with abort. The abort function only ends the program (similar to the exit function).

Printing to standard error or using the assert statement before the abort call would be a good way of achieving this functionality.

You can't specify any message with abort() function call. See the ANSIC standard definition and description of the function abort. And you will get the answer.
Write any string message you want to stdout or to stderr before the abort() call.

#include <stdlib.h>
void abort(void);

The abort function causes abnormal program termination to occur, unless the signal SIGABRT is being caught and the signal handler does not return. Whether open streams with unwritten buffered data are flushed, open streams are closed, or temporary files are removed is implementation-defined. An implementation-defined form of the status unsuccessful terminationis returned to the host environment by means of the function call raise(SIGABRT). The abort function does not return to its caller

Related