Throwing.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- #include <tchar.h>
- using namespace System;
- void func(int a)
- {
- if (a <= 0)
- throw new System::ArgumentException(S"Aaargh!");
- }
- // This is the entry point for this application
- int _tmain(void)
- {
- Console::WriteLine(S"Throw Test");
- try
- {
- int n = 3;
- Console::WriteLine("Calling with n=3");
- func(n);
- Console::WriteLine("Calling with n=0");
- n = 0;
- func(n);
- }
- catch(System::ArgumentException* pex)
- {
- Console::WriteLine("ArgumentException was: {0}", pex->get_Message());
- }
- catch(System::Exception* pex)
- {
- Console::WriteLine("Exception was: {0}", pex->get_Message());
- }
- __finally
- {
- Console::WriteLine("Finally...");
- }
- Console::WriteLine("All done");
- return 0;
- }