home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / exceptions / VCServer / TestExcept.cpp < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.2 KB  |  111 lines

  1. /*+==========================================================================
  2.   File:      TestExcept.cpp
  3.  
  4.   Summary:   This file implements TestExcept and MyCustomException classes 
  5.  
  6.   Classes:   TestExcept, MyCustomException
  7.  
  8.   Functions: CustomException, TestDivideByZero, TestNullReferenceException
  9.  
  10. ----------------------------------------------------------------------------
  11.   This file is part of the Microsoft NGWS Samples.
  12.  
  13.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  14. ==========================================================================+*/
  15.  
  16. #using <mscorlib.dll>
  17. using namespace System;
  18.  
  19. #define NULL 0
  20.  
  21. namespace MyTestException 
  22. {
  23.  
  24. __gc public class MyCustomException : public ApplicationException
  25. {
  26. public:
  27.     
  28.     MyCustomException():ApplicationException(L"MyCustomException")
  29.     {   
  30.         //Exception::SetErrorCode(0x80040001);
  31.         SetHelpLink(L"http://something.com/help.html");
  32.     }
  33.  
  34. };
  35.  
  36. // define the class TestExcept
  37. __gc public class TestExcept
  38. {
  39. public:
  40. /******************************************************************************
  41. Function : CustomException(bool bThrowException)
  42.  
  43. Abstract: It does nothing, just prints out the Method name, unless 
  44.           bThrowException is true, in which case, MyCustomException is thrown.
  45.  
  46. Input Parameters: bool (if true, this function throws a MyCustomException)
  47.  
  48. Returns: String
  49. ******************************************************************************/
  50.     String* CustomException(bool bThrowException)
  51.     {
  52.         Console::WriteLine(L"VC TestExcept.CustomException");
  53.         if(bThrowException)
  54.         {
  55.             throw new MyCustomException();
  56.         }
  57.         
  58.         return L"Done...Not Thrown CustomException";
  59.     }
  60.  
  61. /******************************************************************************
  62. Function : TestDivideByZero(bool bThrowException)
  63.  
  64. Abstract: It does nothing, just prints out the Method name, unless 
  65.           bThrowException is true, in which case, a DivideByZeroException is 
  66.           thrown.
  67.  
  68. Input Parameters: bool (if true, this function throws a MyCustomException)
  69.  
  70. Returns: String
  71. ******************************************************************************/
  72.     String* TestDivideByZero(bool bThrowException)
  73.     {
  74.         Console::WriteLine(L"VC TestExcept.TestDivideByZero");
  75.         if(bThrowException)
  76.         {
  77.             int x = 0;
  78.             int y = 5 / x;
  79.             Console::WriteLine(y);
  80.         }
  81.         
  82.         return L"Done...Not Thrown TestDivideByZero";
  83.     }
  84.  
  85. /******************************************************************************
  86. Function : TestNullReferenceException(bool bThrowException)
  87.  
  88. Abstract: It does nothing, just prints out the Method name, unless 
  89.           bThrowException is true, in which case, a NullReferenceException is 
  90.           thrown.
  91.  
  92. Input Parameters: bool (if true, this function throws a MyCustomException)
  93.  
  94. Returns: String
  95. ******************************************************************************/
  96.     String* TestNullReferenceException(bool bThrowException)
  97.     {
  98.         Console::WriteLine(L"VC TestExcept.TestNullReferenceException");
  99.         if(bThrowException)
  100.         {
  101.             Object *o = NULL;
  102.             Console::WriteLine(o->ToString());
  103.         }
  104.         
  105.         return L"Done...Not Thrown TestNullReferenceException";
  106.     }
  107.  
  108. };
  109.  
  110. };
  111.