📄 excep2.cpp
字号:
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
//
// excep2.cpp. Test program for exception handling.
// compile this program with the following command line
//
// cl -GX excep2.cpp user32.lib
//
// The -GX enables exception handling. The user32.lib provides
// the MessageBox function.
//
void TestFileFunc ();
void TestCharFunc ();
void TestIntFunc ();
int g_Var1 = 0;
int g_Var2 = 0;
int g_Var3 = 0;
main ()
{
try
{
TestCharFunc ();
}
catch (char *ErrorMsg)
{
MessageBox (NULL, ErrorMsg, "Howdy", MB_OK);
}
try
{
TestIntFunc ();
}
catch (int x)
{
MessageBox (NULL, "Caught int exception", "Howdy", MB_OK);
}
try
{
TestFileFunc ();
}
catch (long lx)
{
MessageBox (NULL, "Caught long exception", "Howdy", MB_OK);
}
cout << "g_Var1 = " << g_Var1 << endl;
cout << "g_Var2 = " << g_Var2 << endl;
cout << "g_Var3 = " << g_Var3 << endl;
}
void TestIntFunc()
{
g_Var1 = 10;
throw (-1);
}
void TestCharFunc()
{
g_Var2 = 20;
throw ("Error condition message");
}
void TestFileFunc()
{
g_Var3 = 30;
throw (-1L);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -