Collapse the table of content
Expand the table of content


Modifies __error_mode to determine a non-default location where the C runtime writes an error message for an error that might end the program.

Important note Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

int _set_error_mode(
   int modeval 


Destination of error messages.

Returns the old setting or -1 if an error occurs.

Controls the error output sink by setting the value of __error_mode. For example, you can direct output to a standard error or use the MessageBox API.

The modeval parameter can be set to one of the following values.




Error sink is determined by __app_type.


Error sink is a standard error.


Error sink is a message box.


Report the current __error_mode value.

If a value other than those listed 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 it's used with an assert, _set_error_mode displays the failed statement in the dialog box and gives you the option of choosing the Ignore button so that you can continue to run the program.


Required header



// crt_set_error_mode.c
// compile with: /c
#include <stdlib.h>
#include <assert.h>

int main()
Assertion failed: 2+2==5, file crt_set_error_mode.c, line 8

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