Share via


_set_error_mode

修改 __error_mode 來判斷非預設位置,其中 C 執行階段寫入可能結束程式之錯誤的錯誤訊息。

重要

這個 API 不能用於在 Windows 執行階段中執行的應用程式。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。

語法

int _set_error_mode(
   int mode_val
);

參數

mode_val
錯誤訊息的目的地。

傳回值

如果發生錯誤,則會傳回舊設定或 -1。

備註

設定 __error_mode 的值,以控制錯誤輸出接收。 例如,您可以將輸出導向至標準錯誤,或使用 MessageBox API。

可以將 mode_val 參數設為下列其中一個值。

Description
_OUT_TO_DEFAULT 錯誤接收是透過 __app_type 所決定。
_OUT_TO_STDERR 錯誤接收是標準錯誤。
_OUT_TO_MSGBOX 錯誤接收是訊息方塊。
_REPORT_ERRMODE 報告目前 __error_mode 值。

如果值是在列出的值以外傳入,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,_set_error_mode 會將 errno 設為 EINVAL,並傳回 -1。

與 搭配 使用 assert 時, _set_error_mode 會顯示對話方塊中失敗的 語句,並提供您選擇 [忽略 ] 按鈕的選項,以便繼續執行程式。

需求

常式 必要的標頭
_set_error_mode <stdlib.h>

範例

// 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);
}
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.

另請參閱

assert 巨集、_assert、_wassert