home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / exceptions / VBServer / TestExcept.vb < prev   
Encoding:
Text File  |  2000-06-23  |  3.2 KB  |  90 lines

  1. '+==========================================================================
  2. '  File:      TestExcept.cls
  3. '
  4. '  Summary:   This file implements the TestExcept class
  5. '
  6. '  Classes:   TestExcept
  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. Option Strict Off
  16.  
  17. Imports System
  18. Imports Microsoft.VisualBasic
  19.  
  20. NameSpace MyTestException
  21. Public Class TestExcept
  22.  
  23. '******************************************************************************
  24. 'Function : CustomException(ByVal bThrowException As Boolean) As String
  25. '
  26. 'Abstract: It does nothing, just prints out the Method name, unless 
  27. '          bThrowException is true, in which case, MyCustomException is thrown.
  28. '
  29. 'Input Parameters: Boolean (if true, this function throws a MyCustomException)
  30. 'Returns: String
  31. '******************************************************************************
  32. Public Function CustomException(ByVal bThrowException As Boolean) As String
  33.     Console.WriteLine ("VB TestExcept.CustomException")
  34.     If bThrowException Then
  35.         Dim Except as MyCustomException
  36.         Except = New MyCustomException()
  37.         Throw (Except)
  38.     End If
  39.     
  40.     CustomException = "Done...Not Thrown CustomException"
  41. End Function
  42.  
  43. '******************************************************************************
  44. 'Function : TestDivideByZero(ByVal bThrowException As Boolean) As String
  45. '
  46. 'Abstract: It does nothing, just prints out the Method name, unless 
  47. '          bThrowException is true, in which case, a DivideByZeroException is 
  48. '          thrown.
  49. '
  50. 'Input Parameters: Boolean (if true, this function throws a MyCustomException)
  51. 'Returns: String
  52. '******************************************************************************
  53. Public Function TestDivideByZero(ByVal bThrowException As Boolean) As String
  54.     Console.WriteLine ("VB TestExcept.TestDivideByZero")
  55.     If bThrowException Then
  56.         Dim x As Integer
  57.         Dim y As Integer
  58.         x = 0
  59.         y = 5 / x
  60.         Console.WriteLine (y)
  61.     End If
  62.         
  63.     TestDivideByZero = "Done...Not Thrown TestDivideByZero"
  64. End Function
  65.  
  66. '******************************************************************************
  67. 'Function : TestNullReferenceException(ByVal bThrowException As Boolean) As String
  68. '
  69. 'Abstract: It does nothing, just prints out the Method name, unless 
  70. '          bThrowException is true, in which case, a NullReferenceException is 
  71. '          thrown.
  72. '
  73. 'Input Parameters: Boolean (if true, this function throws a MyCustomException)
  74. 'Returns: String
  75. '******************************************************************************
  76. Public Function TestNullReferenceException(ByVal bThrowException As Boolean) As String
  77.     Console.WriteLine ("VB TestExcept.TestNullReferenceException")
  78.     Dim o as String
  79.     If bThrowException Then
  80.         Dim i as Integer
  81.         i = o.Length
  82.     End If
  83.     
  84.     TestNullReferenceException = "Done...Not Thrown TestNullReferenceException"
  85. End Function
  86. End Class
  87. End Namespace