Export (0) Print
Expand All
div
Expand Minimize

abort

Aborts the current process and returns an error code.

void abort( void );

Return Value

abort does not return control to the calling process. By default, it terminates the current process and returns an exit code of 3.

Remarks

The abort routine prints the message "abnormal program termination" and then calls raise(SIGABRT). The action taken in response to the SIGABRT signal depends on what action has been defined for that signal in a prior call to the signal function. The default SIGABRT action is for the calling process to terminate with exit code 3, returning control to the calling process or operating system. abort does not flush stream buffers or do atexit/_onexit processing.

abort determines the destination of the message based on the type of application that called the routine. Console applications always receive the message through stderr. In a single or multithreaded Windows application, abort calls the Windows MessageBox API to create a message box to display the message with an OK button. When the user clicks OK, the program aborts immediately.

When the application is linked with a debug version of the run-time libraries, abort creates a message box with three buttons: Abort, Retry, and Ignore. If the user clicks Abort, the program aborts immediately. If the user clicks Retry, the debugger is called and the user can debug the program if just-in-time (JIT) debugging is enabled. If the user clicks Ignore, abort continues with its normal execution: creating the message box with the OK button.

For more information on CRT debugging, see CRT Debugging Techniques.

Requirements

Routine Required header Compatibility
abort <process.h> or <stdlib.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

The following program tries to open a file and aborts if the attempt fails.

// crt_abort.c
#include  <stdio.h>
#include  <stdlib.h>

int main( void )
{
   FILE *stream;

   if( (stream = fopen( "NOSUCHF.ILE", "r" )) == NULL )
   {
      perror( "Couldn't open file" );
      abort();
   }
   else
      fclose( stream );
}

Output

Couldn't open file: No such file or directory

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

See Also

Process and Environment Control Routines | _exec Function Overview | exit, raise | signal | _spawn Function Overview | _DEBUG | Run-Time Routines and .NET Framework Equivalents

Show:
© 2014 Microsoft