Rethrow.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)
- {
- try
- {
- if (a <= 0)
- throw new System::ArgumentException(S"Aargh!");
- }
- catch(System::ArgumentException* pex)
- {
- Console::WriteLine("Exception caught in func()");
- throw; // rethrow the exception
- }
- }
- // This is the entry point for this application
- int _tmain(void)
- {
- Console::WriteLine(S"Throw Test");
- try
- {
- int n = 0;
- Console::WriteLine(S"Calling with n=0");
- func(n);
- }
- catch(System::ArgumentException* pex)
- {
- Console::WriteLine(S"Exception caught in main_tmain()");
- }
- __finally
- {
- Console::WriteLine(S"This is the __finally block");
- }
- Console::WriteLine(S"All done");
- return 0;
- }