|
1 |
| ---- |
2 |
| -title: "abort | Microsoft Docs" |
3 |
| -ms.custom: "" |
4 |
| -ms.date: "1/02/2018" |
5 |
| -ms.reviewer: "" |
6 |
| -ms.suite: "" |
7 |
| -ms.technology: ["cpp-standard-libraries"] |
8 |
| -ms.tgt_pltfrm: "" |
9 |
| -ms.topic: "article" |
10 |
| -apiname: ["abort"] |
11 |
| -apilocation: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-runtime-l1-1-0.dll"] |
12 |
| -apitype: "DLLExport" |
13 |
| -f1_keywords: ["Abort"] |
14 |
| -dev_langs: ["C++"] |
15 |
| -helpviewer_keywords: ["aborting current process", "abort function", "processes, aborting"] |
16 |
| -author: "corob-msft" |
17 |
| -ms.author: "corob" |
18 |
| -manager: "ghogen" |
19 |
| -ms.workload: ["cplusplus"] |
20 |
| ---- |
21 |
| -# abort |
22 |
| - |
23 |
| -Aborts the current process and returns an error code. |
24 |
| - |
25 |
| -> [!NOTE] |
26 |
| -> Do not use this method to shut down a Microsoft Store app or Universal Windows Platform (UWP) app, except in testing or debugging scenarios. Programmatic or UI ways to close a Store app are not permitted according to the [Microsoft Store policies](/legal/windows/agreements/store-policies). For more information, see [UWP app lifecycle](/windows/uwp/launch-resume/app-lifecycle). |
27 |
| -
|
28 |
| -## Syntax |
29 |
| - |
30 |
| -```c |
31 |
| -void abort( void ); |
32 |
| -``` |
33 |
| -
|
34 |
| -## Return Value |
35 |
| -
|
36 |
| -`abort` does not return control to the calling process. By default, it checks for an abort signal handler and raises `SIGABRT` if one is set. Then `abort` terminates the current process and returns an exit code to the parent process. |
37 |
| -
|
38 |
| -## Remarks |
39 |
| -
|
40 |
| -**Microsoft Specific** |
41 |
| -
|
42 |
| -By default, when an app is built with the debug runtime library, the `abort` routine displays an error message before `SIGABRT` is raised. For console apps running in console mode, the message is sent to `STDERR`. Windows desktop apps and console apps running in windowed mode display the message in a message box. To suppress the message, use [_set_abort_behavior](../../c-runtime-library/reference/set-abort-behavior.md) to clear the `_WRITE_ABORT_MSG` flag. The message displayed depends on the version of the runtime environment used. For applications built by using the most recent versions of Visual C++, the message resembles this: |
43 |
| -
|
44 |
| -> R6010 - abort() has been called |
45 |
| -
|
46 |
| -In previous versions of the C runtime library, this message was displayed: |
47 |
| -
|
48 |
| -> This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. |
49 |
| -
|
50 |
| -When the program is compiled in debug mode, the message box displays options to **Abort**, **Retry**, or **Ignore**. If the user chooses **Abort**, the program terminates immediately and returns an exit code of 3. If the user chooses **Retry**, a debugger is invoked for just-in-time debugging, if available. If the user chooses **Ignore**, `abort` continues normal processing. |
51 |
| -
|
52 |
| -In both retail and debug builds, `abort` then checks whether an abort signal handler is set. If a non-default signal handler is set, `abort` calls `raise(SIGABRT)`. Use the [signal](../../c-runtime-library/reference/signal.md) function to associate an abort signal handler function with the `SIGABRT` signal. You can perform custom actions—for example, clean up resources or log information—and terminate the app with your own error code in the handler function. If no custom signal handler is defined, `abort` does not raise the `SIGABRT` signal. |
53 |
| -
|
54 |
| -By default, in non-debug builds of desktop or console apps, `abort` then invokes the Windows Error Reporting Service mechanism (formerly known as Dr. Watson) to report failures to Microsoft. This behavior can be enabled or disabled by calling `_set_abort_behavior` and setting or masking the `_CALL_REPORTFAULT` flag. When the flag is set, Windows displays a message box that has text something like "A problem caused the program to stop working correctly." The user can choose to invoke a debugger with a **Debug** button, or choose the **Close program** button to terminate the app with an error code that's defined by the operating system. |
55 |
| -
|
56 |
| -If the Windows error reporting handler is not invoked, then `abort` calls [_exit](../../c-runtime-library/reference/exit-exit-exit.md) to terminate the process with exit code 3 and returns control to the parent process or the operating system. `_exit` does not flush stream buffers or do `atexit`/`_onexit` processing. |
57 |
| -
|
58 |
| -For more information about CRT debugging, see [CRT Debugging Techniques](/visualstudio/debugger/crt-debugging-techniques). |
59 |
| -
|
60 |
| -**End Microsoft Specific** |
61 |
| -
|
62 |
| -## Requirements |
63 |
| -
|
64 |
| -|Routine|Required header| |
65 |
| -|-------------|---------------------| |
66 |
| -|`abort`|\<process.h> or \<stdlib.h>| |
67 |
| -
|
68 |
| -## Example |
69 |
| -
|
70 |
| -The following program tries to open a file and aborts if the attempt fails. |
71 |
| -
|
72 |
| -```C |
73 |
| -// crt_abort.c |
74 |
| -// compile with: /TC |
75 |
| -// This program demonstrates the use of |
76 |
| -// the abort function by attempting to open a file |
77 |
| -// and aborts if the attempt fails. |
78 |
| -
|
79 |
| -#include <stdio.h> |
80 |
| -#include <stdlib.h> |
81 |
| -
|
82 |
| -int main( void ) |
83 |
| -{ |
84 |
| - FILE *stream = NULL; |
85 |
| - errno_t err = 0; |
86 |
| -
|
87 |
| - err = fopen_s(&stream, "NOSUCHF.ILE", "r" ); |
88 |
| - if ((err != 0) || (stream == NULL)) |
89 |
| - { |
90 |
| - perror( "File could not be opened" ); |
91 |
| - abort(); |
92 |
| - } |
93 |
| - else |
94 |
| - { |
95 |
| - fclose( stream ); |
96 |
| - } |
97 |
| -} |
98 |
| -``` |
99 |
| - |
100 |
| -```Output |
101 |
| -File could not be opened: No such file or directory |
102 |
| -``` |
103 |
| - |
104 |
| -## See also |
105 |
| - |
106 |
| -[Using abort](../../cpp/using-abort.md) |
107 |
| -[abort Function](../../c-language/abort-function-c.md) |
108 |
| -[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md) |
109 |
| -[_exec, _wexec Functions](../../c-runtime-library/exec-wexec-functions.md) |
110 |
| -[exit, _Exit, _exit](../../c-runtime-library/reference/exit-exit-exit.md) |
111 |
| -[raise](../../c-runtime-library/reference/raise.md) |
112 |
| -[signal](../../c-runtime-library/reference/signal.md) |
113 |
| -[_spawn, _wspawn Functions](../../c-runtime-library/spawn-wspawn-functions.md) |
114 |
| -[_DEBUG](../../c-runtime-library/debug.md) |
115 |
| -[_set_abort_behavior](../../c-runtime-library/reference/set-abort-behavior.md) |
| 1 | +--- |
| 2 | +title: "abort | Microsoft Docs" |
| 3 | +ms.custom: "" |
| 4 | +ms.date: "1/02/2018" |
| 5 | +ms.reviewer: "" |
| 6 | +ms.suite: "" |
| 7 | +ms.technology: ["cpp-standard-libraries"] |
| 8 | +ms.tgt_pltfrm: "" |
| 9 | +ms.topic: "reference" |
| 10 | +apiname: ["abort"] |
| 11 | +apilocation: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-runtime-l1-1-0.dll"] |
| 12 | +apitype: "DLLExport" |
| 13 | +f1_keywords: ["Abort"] |
| 14 | +dev_langs: ["C++"] |
| 15 | +helpviewer_keywords: ["aborting current process", "abort function", "processes, aborting"] |
| 16 | +author: "corob-msft" |
| 17 | +ms.author: "corob" |
| 18 | +manager: "ghogen" |
| 19 | +ms.workload: ["cplusplus"] |
| 20 | +--- |
| 21 | +# abort |
| 22 | + |
| 23 | +Aborts the current process and returns an error code. |
| 24 | + |
| 25 | +> [!NOTE] |
| 26 | +> Do not use this method to shut down a Microsoft Store app or Universal Windows Platform (UWP) app, except in testing or debugging scenarios. Programmatic or UI ways to close a Store app are not permitted according to the [Microsoft Store policies](/legal/windows/agreements/store-policies). For more information, see [UWP app lifecycle](/windows/uwp/launch-resume/app-lifecycle). |
| 27 | +
|
| 28 | +## Syntax |
| 29 | + |
| 30 | +```c |
| 31 | +void abort( void ); |
| 32 | +``` |
| 33 | +
|
| 34 | +## Return Value |
| 35 | +
|
| 36 | +`abort` does not return control to the calling process. By default, it checks for an abort signal handler and raises `SIGABRT` if one is set. Then `abort` terminates the current process and returns an exit code to the parent process. |
| 37 | +
|
| 38 | +## Remarks |
| 39 | +
|
| 40 | +**Microsoft Specific** |
| 41 | +
|
| 42 | +By default, when an app is built with the debug runtime library, the `abort` routine displays an error message before `SIGABRT` is raised. For console apps running in console mode, the message is sent to `STDERR`. Windows desktop apps and console apps running in windowed mode display the message in a message box. To suppress the message, use [_set_abort_behavior](../../c-runtime-library/reference/set-abort-behavior.md) to clear the `_WRITE_ABORT_MSG` flag. The message displayed depends on the version of the runtime environment used. For applications built by using the most recent versions of Visual C++, the message resembles this: |
| 43 | +
|
| 44 | +> R6010 - abort() has been called |
| 45 | +
|
| 46 | +In previous versions of the C runtime library, this message was displayed: |
| 47 | +
|
| 48 | +> This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. |
| 49 | +
|
| 50 | +When the program is compiled in debug mode, the message box displays options to **Abort**, **Retry**, or **Ignore**. If the user chooses **Abort**, the program terminates immediately and returns an exit code of 3. If the user chooses **Retry**, a debugger is invoked for just-in-time debugging, if available. If the user chooses **Ignore**, `abort` continues normal processing. |
| 51 | +
|
| 52 | +In both retail and debug builds, `abort` then checks whether an abort signal handler is set. If a non-default signal handler is set, `abort` calls `raise(SIGABRT)`. Use the [signal](../../c-runtime-library/reference/signal.md) function to associate an abort signal handler function with the `SIGABRT` signal. You can perform custom actions—for example, clean up resources or log information—and terminate the app with your own error code in the handler function. If no custom signal handler is defined, `abort` does not raise the `SIGABRT` signal. |
| 53 | +
|
| 54 | +By default, in non-debug builds of desktop or console apps, `abort` then invokes the Windows Error Reporting Service mechanism (formerly known as Dr. Watson) to report failures to Microsoft. This behavior can be enabled or disabled by calling `_set_abort_behavior` and setting or masking the `_CALL_REPORTFAULT` flag. When the flag is set, Windows displays a message box that has text something like "A problem caused the program to stop working correctly." The user can choose to invoke a debugger with a **Debug** button, or choose the **Close program** button to terminate the app with an error code that's defined by the operating system. |
| 55 | +
|
| 56 | +If the Windows error reporting handler is not invoked, then `abort` calls [_exit](../../c-runtime-library/reference/exit-exit-exit.md) to terminate the process with exit code 3 and returns control to the parent process or the operating system. `_exit` does not flush stream buffers or do `atexit`/`_onexit` processing. |
| 57 | +
|
| 58 | +For more information about CRT debugging, see [CRT Debugging Techniques](/visualstudio/debugger/crt-debugging-techniques). |
| 59 | +
|
| 60 | +**End Microsoft Specific** |
| 61 | +
|
| 62 | +## Requirements |
| 63 | +
|
| 64 | +|Routine|Required header| |
| 65 | +|-------------|---------------------| |
| 66 | +|`abort`|\<process.h> or \<stdlib.h>| |
| 67 | +
|
| 68 | +## Example |
| 69 | +
|
| 70 | +The following program tries to open a file and aborts if the attempt fails. |
| 71 | +
|
| 72 | +```C |
| 73 | +// crt_abort.c |
| 74 | +// compile with: /TC |
| 75 | +// This program demonstrates the use of |
| 76 | +// the abort function by attempting to open a file |
| 77 | +// and aborts if the attempt fails. |
| 78 | +
|
| 79 | +#include <stdio.h> |
| 80 | +#include <stdlib.h> |
| 81 | +
|
| 82 | +int main( void ) |
| 83 | +{ |
| 84 | + FILE *stream = NULL; |
| 85 | + errno_t err = 0; |
| 86 | +
|
| 87 | + err = fopen_s(&stream, "NOSUCHF.ILE", "r" ); |
| 88 | + if ((err != 0) || (stream == NULL)) |
| 89 | + { |
| 90 | + perror( "File could not be opened" ); |
| 91 | + abort(); |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + fclose( stream ); |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +```Output |
| 101 | +File could not be opened: No such file or directory |
| 102 | +``` |
| 103 | + |
| 104 | +## See also |
| 105 | + |
| 106 | +[Using abort](../../cpp/using-abort.md) |
| 107 | +[abort Function](../../c-language/abort-function-c.md) |
| 108 | +[Process and Environment Control](../../c-runtime-library/process-and-environment-control.md) |
| 109 | +[_exec, _wexec Functions](../../c-runtime-library/exec-wexec-functions.md) |
| 110 | +[exit, _Exit, _exit](../../c-runtime-library/reference/exit-exit-exit.md) |
| 111 | +[raise](../../c-runtime-library/reference/raise.md) |
| 112 | +[signal](../../c-runtime-library/reference/signal.md) |
| 113 | +[_spawn, _wspawn Functions](../../c-runtime-library/spawn-wspawn-functions.md) |
| 114 | +[_DEBUG](../../c-runtime-library/debug.md) |
| 115 | +[_set_abort_behavior](../../c-runtime-library/reference/set-abort-behavior.md) |
| 116 | + |
0 commit comments