home *** CD-ROM | disk | FTP | other *** search
- '+==========================================================================
- ' File: client.vb
- '
- ' Summary: This is the VB exception client.
- '
- ' Classes: None
- '
- ' Functions: ThrowException, main
- '
- '---------------------------------------------------------------------------
- ' This file is part of the Microsoft NGWS Samples.
- '
- ' Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- '=========================================================================
-
- Imports System
- Imports MyTestException
-
-
-
- Module Client1
- Const THROW_CUSTOMEXCEPTION As Integer = 1
- Const THROW_DIVIDEBYZEROEXCEPTION As Integer = 2
- Const THROW_NULLREFERENCEEXCEPTION As Integer = 3
-
-
- '*****************************************************************************
- ' Sub : ThrowException
- '
- ' Abstract: Invokes a method on TestExcept which will optionally throw an
- ' exception and will by caught by this method.
- ' on the class
- '
- ' Input Parameters: TestExcept (class which will throw exceptions)
- ' type (the type of exception to throw)
- ' do_throw (throw the exception)
- '
- ' Returns: None
- '******************************************************************************
- Sub ThrowException(ByVal tst As MyTestException.TestExcept, _
- ByVal typ as Integer, ByVal do_throw As Boolean)
- ' Enable Runtime Exception Catching
- Try
-
- Console.WriteLine ("================================" & _
- "================================")
-
- Dim myString as String
-
- If typ = THROW_CUSTOMEXCEPTION Then
- myString = tst.CustomException(do_throw)
- ElseIf typ = THROW_DIVIDEBYZEROEXCEPTION Then
- myString = tst.TestDivideByZero(do_throw)
- ElseIf typ = THROW_NULLREFERENCEEXCEPTION Then
- myString = tst.TestNullReferenceException(do_throw)
- End If
-
- Console.WriteLine( myString)
- Catch e As Exception
- Console.WriteLine ("Exception: " & e.ToString())
- Console.WriteLine ("Message: " & e.Message)
- Console.WriteLine ("Stack Trace: " & e.StackTrace)
- Console.WriteLine ("Help Link: " & e.HelpLink)
- 'Console.WriteLine ("ErrorCode: " & Convert.ToString(e.errorCode))
- End Try
- End Sub
-
- '*****************************************************************************
- ' Sub : main
- '
- ' Abstract: Creates an instance of the TestExcept class and will invokes its
- ' various methods to have it throw and let us catch exceptions.
- '
- ' Input Parameters: None
- '
- ' Returns: None
- '*****************************************************************************
- Sub Main()
- Dim tst as MyTestException.TestExcept
- tst = new MyTestException.TestExcept
-
- ThrowException (tst, THROW_CUSTOMEXCEPTION, False)
- ThrowException (tst, THROW_DIVIDEBYZEROEXCEPTION, False)
- ThrowException (tst, THROW_NULLREFERENCEEXCEPTION, False)
-
- ThrowException (tst, THROW_CUSTOMEXCEPTION, True)
- ThrowException (tst, THROW_DIVIDEBYZEROEXCEPTION, True)
- ThrowException (tst, THROW_NULLREFERENCEEXCEPTION, True)
-
- Console.WriteLine ("Done")
- End Sub
-
- End Module