You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**`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.
27
+
**`abort`** doesn't 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.
28
28
29
29
## Remarks
30
30
31
31
**Microsoft Specific**
32
32
33
-
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`](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:
33
+
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`](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 one:
34
34
35
35
> R6010 - abort() has been called
36
36
@@ -40,17 +40,19 @@ In previous versions of the C runtime library, this message was displayed:
40
40
41
41
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.
42
42
43
-
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`](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.
43
+
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`](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`** doesn't raise the `SIGABRT` signal.
44
44
45
45
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.
46
46
47
-
If the Windows error reporting handler is not invoked, then **`abort`** calls [`_exit`](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.
47
+
If the Windows error reporting handler isn't invoked, then **`abort`** calls [`_exit`](exit-exit-exit.md) to terminate the process with exit code 3 and returns control to the parent process or the operating system. `_exit` doesn't flush stream buffers or do `atexit`/`_onexit` processing.
48
+
49
+
For Windows compatibility reasons, when `abort` calls `_exit`, it may invoke the Windows [`ExitProcess`](/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess) API, which in turn allows DLL termination routines to run. Destructors aren't run in the executable, but the same may not be true of DLLs loaded in the executable's process space. This behavior doesn't strictly conform to the C++ standard. To immediately terminate a process including any DLLs, use the Windows [`TerminateProcess`](/windows/desktop/api/processthreadsapi/nf-processthreadsapi-terminateprocess) API. You can also register an abort signal handler that invokes `TerminateProcess` for standard-compliant behavior. Compliant behavior may come at some cost in Windows compatibility.
48
50
49
51
For more information about CRT debugging, see [CRT Debugging Techniques](/visualstudio/debugger/crt-debugging-techniques).
50
52
51
53
**End Microsoft Specific**
52
54
53
-
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
55
+
By default, this function's global state is scoped to the application. To change this default, see [Global state in the CRT](../global-state.md).
Specifies the action to be taken when a program is abnormally terminated.
15
15
16
16
> [!NOTE]
17
-
> Do not use the [abort](abort.md) function to shut down a Microsoft Store 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).
17
+
> Do not use the [`abort`](abort.md) function to shut down a Microsoft Store 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).
18
18
19
19
## Syntax
20
20
@@ -27,21 +27,23 @@ unsigned int _set_abort_behavior(
27
27
28
28
### Parameters
29
29
30
-
*flags*<br/>
31
-
New value of the [abort](abort.md) flags.
30
+
*`flags`*\
31
+
New value of the `abort` flags.
32
32
33
-
*mask*<br/>
34
-
Mask for the [abort](abort.md) flags bits to set.
33
+
*`mask`*\
34
+
Mask for the `abort` flags bits to set.
35
35
36
36
## Return Value
37
37
38
38
The old value of the flags.
39
39
40
40
## Remarks
41
41
42
-
There are two [abort](abort.md) flags: **_WRITE_ABORT_MSG** and **_CALL_REPORTFAULT**. **_WRITE_ABORT_MSG** determines whether a helpful text message is printed when a program is abnormally terminated. The message states that the application has called the [abort](abort.md) function. The default behavior is to print the message. **_CALL_REPORTFAULT**, if set, specifies that a Watson crash dump is generated and reported when [abort](abort.md) is called. By default, crash dump reporting is enabled in non-DEBUG builds.
42
+
There are two [`abort`](abort.md) flags: `_WRITE_ABORT_MSG` and `_CALL_REPORTFAULT`. `_WRITE_ABORT_MSG` determines whether a helpful text message is printed when a program is abnormally terminated. The message states that the application has called the `abort` function. The default behavior is to print the message. `_CALL_REPORTFAULT`, if set, invokes the Windows Error Reporting Service mechanism (formerly known as Dr. Watson) to report failures to Microsoft when `abort` is called. By default, crash dump reporting is enabled in non-DEBUG builds. If the Windows error reporting handler isn't invoked, then `abort` calls [`_exit`](exit-exit-exit.md) to terminate the process with exit code 3 and returns control to the parent process or the operating system. `_exit` doesn't flush stream buffers or do `atexit`/`_onexit` processing.
43
43
44
-
By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).
44
+
For Windows compatibility reasons, when `abort` calls `_exit`, it may invoke the Windows [`ExitProcess`](/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess) API, which in turn allows DLL termination routines to run. Destructors aren't run in the executable, but the same may not be true of DLLs loaded in the executable's process space. This behavior doesn't strictly conform to the C++ standard. To immediately terminate a process including any DLLs, use the Windows [`TerminateProcess`](/windows/desktop/api/processthreadsapi/nf-processthreadsapi-terminateprocess) API. You can also register an abort signal handler that invokes `TerminateProcess` for standard-compliant behavior. Compliant behavior may come at some cost in Windows compatibility.
45
+
46
+
By default, this function's global state is scoped to the application. To change it, see [Global state in the CRT](../global-state.md).
45
47
46
48
## Requirements
47
49
@@ -74,4 +76,4 @@ Suppressing the abort message. If successful, this message will be the only outp
@@ -16,35 +16,44 @@ In C++, you can exit a program in these ways:
16
16
17
17
The [`exit`](../c-runtime-library/reference/exit-exit-exit.md) function, declared in \<stdlib.h>, terminates a C++ program. The value supplied as an argument to `exit` is returned to the operating system as the program's return code or exit code. By convention, a return code of zero means that the program completed successfully. You can use the constants `EXIT_FAILURE` and `EXIT_SUCCESS`, also defined in \<stdlib.h>, to indicate success or failure of your program.
18
18
19
-
Issuing a **`return`** statement from the `main` function is equivalent to calling the `exit` function with the return value as its argument.
20
-
21
19
## `abort` function
22
20
23
-
The [`abort`](../c-runtime-library/reference/abort.md) function, also declared in the standard include file \<stdlib.h>, terminates a C++ program. The difference between `exit` and `abort` is that `exit` allows the C++ run-time termination processing to take place (global object destructors get called), but `abort` terminates the program immediately. The `abort` function bypasses the normal destruction process for initialized global static objects. It also bypasses any special processing that was specified using the [`atexit`](../c-runtime-library/reference/atexit.md) function.
21
+
The [`abort`](../c-runtime-library/reference/abort.md) function, also declared in the standard include file \<stdlib.h>, terminates a C++ program. The difference between `exit` and `abort` is that `exit` allows the C++ runtime termination processing to take place (global object destructors get called). `abort` terminates the program immediately. The `abort` function bypasses the normal destruction process for initialized global static objects. It also bypasses any special processing that was specified using the [`atexit`](../c-runtime-library/reference/atexit.md) function.
22
+
23
+
**Microsoft-specific**: For Windows compatibility reasons, the Microsoft implementation of `abort` may allow DLL termination code to run in certain circumstances. For more information, see [`abort`](../c-runtime-library/reference/abort.md).
24
24
25
25
## `atexit` function
26
26
27
27
Use the [`atexit`](../c-runtime-library/reference/atexit.md) function to specify actions that execute before the program terminates. No global static objects initialized before the call to `atexit` are destroyed before execution of the exit-processing function.
28
28
29
29
## `return` statement in `main`
30
30
31
-
Issuing a [`return`](return-statement-cpp.md) statement from`main`is functionally equivalent to calling the `exit`function. Consider the following example:
31
+
The **`return`** statement allows you to specify a return value from `main`. A [`return`](return-statement-cpp.md) statement in`main`first acts like any other `return` statement. Any automatic variables are destroyed. Then, `main` invokes `exit`with the return value as a parameter. Consider the following example:
32
32
33
33
```cpp
34
34
// return_statement.cpp
35
35
#include<stdlib.h>
36
+
structS
37
+
{
38
+
int value;
39
+
};
36
40
intmain()
37
41
{
42
+
S s{ 3 };
43
+
38
44
exit( 3 );
45
+
// or
39
46
return 3;
40
47
}
41
48
```
42
49
43
-
The `exit` and **`return`** statements in the preceding example are functionally identical. Normally, C++ requires that functions that have return types other than **`void`** return a value. The `main` function is an exception; it can end without a **`return`** statement. In that case, it returns an implementation-specific value to the invoking process. The **`return`** statement allows you to specify a return value from `main`.
50
+
The `exit` and **`return`** statements in the preceding example have similar behavior. Both terminate the program and return a value of 3 to the operating system. The difference is that `exit` doesn't destroy the automatic variable `s`, while the `return` statement does.
51
+
52
+
Normally, C++ requires that functions that have return types other than **`void`** return a value. The `main` function is an exception; it can end without a **`return`** statement. In that case, it returns an implementation-specific value to the invoking process. (By default, MSVC returns 0.)
44
53
45
-
## Destruction of static objects
54
+
## Destruction of thread and static objects
46
55
47
-
When you call `exit` or execute a **`return`** statement from `main`, static objects are destroyed in the reverse order of their initialization (after the call to `atexit` if one exists). The following example shows how such initialization and cleanup works.
56
+
When you call `exit`directly (or when it's called after a **`return`** statement from `main`), thread objects associated with the current thread are destroyed. Next, static objects are destroyed in the reverse order of their initialization (after calls to functions specified to `atexit`, if any). The following example shows how such initialization and cleanup works.
48
57
49
58
### Example
50
59
@@ -86,7 +95,7 @@ int main() {
86
95
}
87
96
```
88
97
89
-
Another way to write this code is to declare the `ShowData` objects with block scope, allowing them to be destroyed when they go out of scope:
98
+
Another way to write this code is to declare the `ShowData` objects with block scope, which implicitly destroys them when they go out of scope:
0 commit comments