CtorTest.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;
- __gc class Test
- {
- String* pv;
- public:
- Test(String* pval)
- {
- if (pval == 0 || pval == S"")
- throw new System::ArgumentException("Argument null or blank");
- else
- pval = pv;
- }
- };
- // This is the entry point for this application
- int _tmain(void)
- {
- Console::WriteLine(S"Exceptions in Constructors");
- String* ps = S"abc";
- Test* pt = 0;
- try
- {
- pt = new Test(ps);
- }
- catch(System::ArgumentException* pex)
- {
- Console::WriteLine(S"Exception: {0}", pex->get_Message());
- }
- return 0;
- }