home *** CD-ROM | disk | FTP | other *** search
- /*+==========================================================================
- File: TestExcept.cpp
-
- Summary: This file implements TestExcept and MyCustomException classes
-
- Classes: TestExcept, MyCustomException
-
- Functions: CustomException, TestDivideByZero, TestNullReferenceException
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- ==========================================================================+*/
-
- #using <mscorlib.dll>
- using namespace System;
-
- #define NULL 0
-
- namespace MyTestException
- {
-
- __gc public class MyCustomException : public ApplicationException
- {
- public:
-
- MyCustomException():ApplicationException(L"MyCustomException")
- {
- //Exception::SetErrorCode(0x80040001);
- SetHelpLink(L"http://something.com/help.html");
- }
-
- };
-
- // define the class TestExcept
- __gc public class TestExcept
- {
- public:
- /******************************************************************************
- Function : CustomException(bool bThrowException)
-
- Abstract: It does nothing, just prints out the Method name, unless
- bThrowException is true, in which case, MyCustomException is thrown.
-
- Input Parameters: bool (if true, this function throws a MyCustomException)
-
- Returns: String
- ******************************************************************************/
- String* CustomException(bool bThrowException)
- {
- Console::WriteLine(L"VC TestExcept.CustomException");
- if(bThrowException)
- {
- throw new MyCustomException();
- }
-
- return L"Done...Not Thrown CustomException";
- }
-
- /******************************************************************************
- Function : TestDivideByZero(bool bThrowException)
-
- Abstract: It does nothing, just prints out the Method name, unless
- bThrowException is true, in which case, a DivideByZeroException is
- thrown.
-
- Input Parameters: bool (if true, this function throws a MyCustomException)
-
- Returns: String
- ******************************************************************************/
- String* TestDivideByZero(bool bThrowException)
- {
- Console::WriteLine(L"VC TestExcept.TestDivideByZero");
- if(bThrowException)
- {
- int x = 0;
- int y = 5 / x;
- Console::WriteLine(y);
- }
-
- return L"Done...Not Thrown TestDivideByZero";
- }
-
- /******************************************************************************
- Function : TestNullReferenceException(bool bThrowException)
-
- Abstract: It does nothing, just prints out the Method name, unless
- bThrowException is true, in which case, a NullReferenceException is
- thrown.
-
- Input Parameters: bool (if true, this function throws a MyCustomException)
-
- Returns: String
- ******************************************************************************/
- String* TestNullReferenceException(bool bThrowException)
- {
- Console::WriteLine(L"VC TestExcept.TestNullReferenceException");
- if(bThrowException)
- {
- Object *o = NULL;
- Console::WriteLine(o->ToString());
- }
-
- return L"Done...Not Thrown TestNullReferenceException";
- }
-
- };
-
- };
-