home *** CD-ROM | disk | FTP | other *** search
- //+==========================================================================
- // File: client.il
- //
- // Summary: This is the IL assembler exception client.
- //
- // Classes: None
- //
- // Functions: main, PrintException, ThrowException
- //
- //---------------------------------------------------------------------------
- // This file is part of the Microsoft NGWS Samples.
- //
- // Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- //==========================================================================+
-
- .assembly 'client' { }
- .assembly extern 'mscorlib' { }
- .assembly extern 'MyTestException' { }
- // ****************************************************************************
- // Function: PrintException
- //
- // Abstract: Outputs a description of the System.Exception that
- // was passed into it.
- //
- // Input Parameters: Exception (String that describes the exception)
- //
- // Returns: void
- // ****************************************************************************
- .method static void PrintException(class [mscorlib]System.Exception) {
- .maxstack 3
- .locals ()
-
- // output "Exception: "
- ldstr "Exception: "
- call void [mscorlib]System.Console::Write(class System.String)
- // output System.Exception::ToString()
- ldarg 0x0
- callvirt instance class System.String [mscorlib]System.Exception::ToString()
- call void [mscorlib]System.Console::WriteLine(class System.String)
- // output "Message: "
- ldstr "Message: "
- call void [mscorlib]System.Console::Write(class System.String)
- // output System.Exception::GetMessage() to standard output
- ldarg 0x0
- callvirt instance class System.String [mscorlib]System.Exception::get_Message()
- call void [mscorlib]System.Console::WriteLine(class System.String)
- // output "Stack Trace: "
- ldstr "Stack Trace: "
- call void [mscorlib]System.Console::Write(class System.String)
- // output System.Exception.GetStackTrace() to standard output
- ldarg 0x0
- callvirt instance class System.String [mscorlib]System.Exception::get_StackTrace()
- call void [mscorlib]System.Console::WriteLine(class System.String)
- // output "Help URL: "
- ldstr "Help URL: "
- call void [mscorlib]System.Console::Write(class System.String)
- // output System.Exception::GetHelpLink() to standard output
- ldarg 0x0
- callvirt instance class System.String [mscorlib]System.Exception::get_HelpLink()
- call void [mscorlib]System.Console::WriteLine(class System.String)
-
- EndOfPrintException:
- ret
- }
-
- // ***************************************************************************
- // Function: 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)
- // int32 (the class of exception to _throw)
- // bool (actually _throw the exception)
- //
- // Returns: void
- // ***************************************************************************
- .method static void ThrowException(class [MyTestException]MyTestException.TestExcept,int32,bool) {
- .maxstack 3
- .locals ()
-
- // start the Try block
- StartTry:
-
- ldstr "============================================================="
- call void [mscorlib]System.Console::WriteLine(class System.String)
-
- ldarg 0x1
- switch (dest1,dest2,dest3)
-
- dest1:
- ldarg 0x0
- ldarg 0x2
- callvirt instance class System.String [MyTestException]MyTestException.TestExcept::CustomException(bool)
- br skip
-
- dest2:
- ldarg 0x0
- ldarg 0x2
- callvirt instance class System.String [MyTestException]MyTestException.TestExcept::TestDivideByZero(bool)
- br skip
-
- dest3:
- ldarg 0x0
- ldarg 0x2
- callvirt instance class System.String [MyTestException]MyTestException.TestExcept::TestNullReferenceException(bool)
- br skip
-
- skip:
- call void [mscorlib]System.Console::WriteLine(class System.String)
- leave EndOfThrowException
- // end of the Try block
- EndTry:
-
- // start of Catch block
- BeginCatch:
- ldstr "Caught Exception: "
- call void [mscorlib]System.Console::Write(class System.String)
- call void PrintException(class [mscorlib]System.Exception)
- leave EndOfThrowException
- EndCatch:
- //end of catch Exception block
-
- // start of Finally block
- BeginFinally:
- ldstr "Finally called"
- call void [mscorlib]System.Console::WriteLine(class System.String)
- endfinally
- EndFinally:
- //end Finally block
-
- EndOfThrowException:
- ret
-
- .try StartTry to EndTry catch System.Exception handler BeginCatch to EndCatch
- .try StartTry to EndTry finally handler BeginFinally to EndFinally
- }
-
- // ***************************************************************************
- // Function: 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: void
- // ***************************************************************************
- .method static void main() {
- .entrypoint
- .maxstack 3
- .locals (class [MyTestException]MyTestException.TestExcept)
-
- // create the MyTestException.TestExcept object
- newobj void [MyTestException]MyTestException.TestExcept::.ctor()
- // store the MyTestException.TestExcept object for future use
- stloc 0x0
-
- ldloc 0x0
- ldc.i4 0x0
- ldc.i4 0x0
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldloc 0x0
- ldc.i4 0x1
- ldc.i4 0x0
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldloc 0x0
- ldc.i4 0x2
- ldc.i4 0x0
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldloc 0x0
- ldc.i4 0x0
- ldc.i4 0x1
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldloc 0x0
- ldc.i4 0x1
- ldc.i4 0x1
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldloc 0x0
- ldc.i4 0x2
- ldc.i4 0x1
- call void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
-
- ldstr "Pass"
- call void [mscorlib]System.Console::WriteLine(class System.String)
- ret
-
- }
-