home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / exceptions / VBClient / client.vb next >
Encoding:
Text File  |  2000-06-23  |  3.0 KB  |  93 lines

  1. '+==========================================================================
  2. '  File:      client.vb
  3. '
  4. '  Summary:   This is the VB exception client.
  5. '
  6. '  Classes:   None
  7. '
  8. '  Functions: ThrowException, main
  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. Imports System
  17. Imports MyTestException
  18.  
  19.  
  20.  
  21. Module Client1
  22. Const THROW_CUSTOMEXCEPTION As Integer = 1
  23. Const THROW_DIVIDEBYZEROEXCEPTION As Integer = 2
  24. Const THROW_NULLREFERENCEEXCEPTION As Integer = 3
  25.  
  26.  
  27. '*****************************************************************************
  28. ' Sub     :  ThrowException
  29. '
  30. ' Abstract:  Invokes a method on TestExcept which will optionally throw an
  31. '            exception and will by caught by this method.
  32. '            on the class
  33. '            
  34. ' Input Parameters: TestExcept (class which will throw exceptions)
  35. '                   type (the type of exception to throw)
  36. '                   do_throw (throw the exception)
  37. '
  38. ' Returns: None
  39. '******************************************************************************
  40. Sub ThrowException(ByVal tst As MyTestException.TestExcept, _
  41.         ByVal typ as Integer, ByVal do_throw As Boolean)
  42.     ' Enable Runtime Exception Catching
  43.     Try
  44.  
  45.         Console.WriteLine ("================================" & _
  46.                 "================================")
  47.  
  48.         Dim myString as String
  49.  
  50.         If typ = THROW_CUSTOMEXCEPTION Then
  51.             myString = tst.CustomException(do_throw)
  52.         ElseIf typ = THROW_DIVIDEBYZEROEXCEPTION Then
  53.             myString = tst.TestDivideByZero(do_throw)
  54.         ElseIf typ = THROW_NULLREFERENCEEXCEPTION Then
  55.             myString = tst.TestNullReferenceException(do_throw)
  56.         End If
  57.  
  58.         Console.WriteLine( myString)
  59.     Catch e As Exception
  60.         Console.WriteLine ("Exception: " & e.ToString())
  61.         Console.WriteLine ("Message: " & e.Message)
  62.         Console.WriteLine ("Stack Trace: " & e.StackTrace)
  63.         Console.WriteLine ("Help Link: " & e.HelpLink)
  64.         'Console.WriteLine ("ErrorCode: " & Convert.ToString(e.errorCode))
  65.     End Try
  66. End Sub
  67.  
  68. '*****************************************************************************
  69. ' Sub     : main
  70. '
  71. ' Abstract: Creates an instance of the TestExcept class and will invokes its
  72. '           various methods to have it throw and let us catch exceptions.
  73. '            
  74. ' Input Parameters: None
  75. '
  76. ' Returns: None
  77. '*****************************************************************************
  78. Sub Main()
  79.     Dim tst as MyTestException.TestExcept
  80.     tst = new MyTestException.TestExcept
  81.  
  82.     ThrowException (tst, THROW_CUSTOMEXCEPTION, False)
  83.     ThrowException (tst, THROW_DIVIDEBYZEROEXCEPTION, False)
  84.     ThrowException (tst, THROW_NULLREFERENCEEXCEPTION, False)
  85.  
  86.     ThrowException (tst, THROW_CUSTOMEXCEPTION, True)
  87.     ThrowException (tst, THROW_DIVIDEBYZEROEXCEPTION, True)
  88.     ThrowException (tst, THROW_NULLREFERENCEEXCEPTION, True)
  89.  
  90.     Console.WriteLine ("Done")
  91. End Sub
  92.  
  93. End Module