_set_error_mode
Modifies __error_mode to determine a non-default location where the C run time writes an error message for an error that will possibly end the program.
int _set_error_mode( int modeval );
Controls the error output sink by setting the value of __error_mode. For example, you can direct output to standard error or use the MessageBox API.
The modeval parameter can be set to one of the following.
Parameter | Description |
|---|---|
_OUT_TO_DEFAULT | Error sink is determined by __app_type. |
_OUT_TO_STDERR | Error sink is a standard error. |
_OUT_TO_MSGBOX | Error sink is a message box. |
_REPORT_ERRMODE | Report the current __error_mode value. |
If a value other than those listed above is passed in, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, _set_error_mode sets errno to EINVAL and returns -1.
When used with an assert, _set_error_mode displays the failed statement in the dialog box and give you the option of clicking Ignore, which allows you to continue executing the program.
// crt_set_error_mode.c
// compile with: /c
#include <stdlib.h>
#include <assert.h>
int main()
{
_set_error_mode(_OUT_TO_STDERR);
assert(2+2==5);
}