Condividi tramite


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

By default, the abort routine prints the message:

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

It 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-based application, abort calls the Windows MessageBox function to create a message box to display the message with an OK button. When the user clicks OK, the program aborts immediately. The message can be suppressed by calling _set_abort_behavior with the appropriate arguments.

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.

abort also invokes an error reporting mechanism to report failures to Microsoft. This behavior can be disabled by calling _set_abort_behavior.

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

Requirements

Routine

Required header

abort

<process.h> or <stdlib.h>

Example

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

// crt_abort.c
// compile with: /c
// This program demonstrates the use of
// the abort function by attempting to open a file
// and aborts if the attempt fails.

#include  <stdio.h>
#include  <stdlib.h>

int main( void )
{
    FILE    *stream = NULL;
    errno_t err = 0;

    err = fopen_s(&stream, "NOSUCHF.ILE", "r" );
    if ((err != 0) || (stream == NULL))
    {
        perror( "File could not be opened" );
        abort();
    }
    else
    {
        fclose( stream );
    }
}
File could not be opened: 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.

.NET Framework Equivalent

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

See Also

Reference

Using abort

abort Function (C)

Process and Environment Control

_exec, _wexec Functions

exit, _exit

raise

signal

_spawn, _wspawn Functions

_DEBUG

_set_abort_behavior