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

  1. //+==========================================================================
  2. //  File:      client.il
  3. //
  4. //  Summary:   This is the IL assembler exception client.
  5. //
  6. //  Classes:   None
  7. //
  8. //  Functions: main, PrintException, ThrowException
  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. .assembly 'client' { }
  17. .assembly extern 'mscorlib' { }
  18. .assembly extern 'MyTestException' { }
  19. // ****************************************************************************
  20. // Function:  PrintException
  21. //
  22. // Abstract:  Outputs a description of the System.Exception that
  23. //            was passed into it.
  24. //            
  25. // Input Parameters: Exception (String that describes the exception)
  26. //
  27. // Returns: void
  28. // ****************************************************************************
  29. .method            static void PrintException(class [mscorlib]System.Exception) {
  30. .maxstack        3
  31. .locals        ()
  32.  
  33. // output "Exception: "
  34. ldstr            "Exception: "
  35. call            void [mscorlib]System.Console::Write(class System.String)
  36. // output System.Exception::ToString()
  37. ldarg            0x0
  38. callvirt        instance class System.String [mscorlib]System.Exception::ToString()
  39. call            void [mscorlib]System.Console::WriteLine(class System.String)
  40. // output "Message: "
  41. ldstr            "Message: "
  42. call            void [mscorlib]System.Console::Write(class System.String)
  43. // output System.Exception::GetMessage() to standard output
  44. ldarg            0x0
  45. callvirt        instance class System.String [mscorlib]System.Exception::get_Message()
  46. call            void [mscorlib]System.Console::WriteLine(class System.String)
  47. // output "Stack Trace: "
  48. ldstr            "Stack Trace: "
  49. call            void [mscorlib]System.Console::Write(class System.String)
  50. // output System.Exception.GetStackTrace() to standard output
  51. ldarg            0x0
  52. callvirt        instance class System.String [mscorlib]System.Exception::get_StackTrace()
  53. call            void [mscorlib]System.Console::WriteLine(class System.String)
  54. // output "Help URL: "
  55. ldstr            "Help URL: "
  56. call            void [mscorlib]System.Console::Write(class System.String)
  57. // output System.Exception::GetHelpLink() to standard output
  58. ldarg            0x0
  59. callvirt        instance class System.String [mscorlib]System.Exception::get_HelpLink()
  60. call            void [mscorlib]System.Console::WriteLine(class System.String)
  61.  
  62. EndOfPrintException:
  63. ret
  64. }
  65.  
  66. // ***************************************************************************
  67. // Function:  ThrowException
  68. //
  69. // Abstract:  Invokes a method on TestExcept which will optionally _throw an
  70. //            exception _and will by caught by this method.
  71. //            on the class
  72. //            
  73. // Input Parameters: TestExcept (class which will _throw exceptions)
  74. //                   int32 (the class of exception to _throw)
  75. //                   bool (actually _throw the exception)
  76. //
  77. // Returns: void
  78. // ***************************************************************************
  79. .method            static void ThrowException(class [MyTestException]MyTestException.TestExcept,int32,bool) {
  80. .maxstack        3
  81. .locals        ()
  82.  
  83. // start the Try block
  84. StartTry:
  85.  
  86. ldstr            "============================================================="
  87. call            void [mscorlib]System.Console::WriteLine(class System.String)
  88.  
  89. ldarg            0x1
  90. switch (dest1,dest2,dest3)
  91.  
  92. dest1:
  93. ldarg            0x0
  94. ldarg            0x2
  95. callvirt        instance class System.String [MyTestException]MyTestException.TestExcept::CustomException(bool)
  96. br                skip
  97.  
  98. dest2:
  99. ldarg            0x0
  100. ldarg            0x2
  101. callvirt        instance class System.String [MyTestException]MyTestException.TestExcept::TestDivideByZero(bool)
  102. br                skip
  103.  
  104. dest3:
  105. ldarg            0x0
  106. ldarg            0x2
  107. callvirt        instance class System.String [MyTestException]MyTestException.TestExcept::TestNullReferenceException(bool)
  108. br                skip
  109.  
  110. skip:
  111. call            void [mscorlib]System.Console::WriteLine(class System.String)
  112. leave            EndOfThrowException
  113. // end of the Try block
  114. EndTry:
  115.  
  116. // start of Catch block
  117. BeginCatch:
  118. ldstr            "Caught Exception: "
  119. call            void [mscorlib]System.Console::Write(class System.String)
  120. call            void PrintException(class [mscorlib]System.Exception)
  121. leave            EndOfThrowException
  122. EndCatch:
  123. //end of catch Exception block
  124.  
  125. // start of Finally block
  126. BeginFinally:
  127. ldstr            "Finally called"
  128. call            void [mscorlib]System.Console::WriteLine(class System.String)
  129. endfinally
  130. EndFinally:
  131. //end Finally block
  132.  
  133. EndOfThrowException:
  134. ret
  135.  
  136. .try StartTry to EndTry catch System.Exception handler BeginCatch to EndCatch
  137. .try StartTry to EndTry finally handler BeginFinally to EndFinally
  138. }
  139.  
  140. // ***************************************************************************
  141. // Function: main
  142. //
  143. // Abstract: Creates an instance of the TestExcept class _and will invokes its
  144. //           various methods to have it _throw _and let us catch exceptions.
  145. //            
  146. // Input Parameters: None
  147. //
  148. // Returns: void
  149. // ***************************************************************************
  150. .method            static void main() {
  151. .entrypoint
  152. .maxstack        3
  153. .locals        (class [MyTestException]MyTestException.TestExcept)
  154.  
  155. // create the MyTestException.TestExcept object
  156. newobj            void [MyTestException]MyTestException.TestExcept::.ctor()
  157. // store the MyTestException.TestExcept object for future use
  158. stloc            0x0
  159.  
  160. ldloc            0x0
  161. ldc.i4            0x0
  162. ldc.i4            0x0
  163. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  164.  
  165. ldloc            0x0
  166. ldc.i4            0x1
  167. ldc.i4            0x0
  168. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  169.  
  170. ldloc            0x0
  171. ldc.i4            0x2
  172. ldc.i4            0x0
  173. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  174.  
  175. ldloc            0x0
  176. ldc.i4            0x0
  177. ldc.i4            0x1
  178. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  179.  
  180. ldloc            0x0
  181. ldc.i4            0x1
  182. ldc.i4            0x1
  183. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  184.  
  185. ldloc            0x0
  186. ldc.i4            0x2
  187. ldc.i4            0x1
  188. call            void ThrowException(class [MyTestException]MyTestException.TestExcept, int32, bool)
  189.  
  190. ldstr            "Pass"
  191. call            void [mscorlib]System.Console::WriteLine(class System.String)
  192. ret
  193.  
  194. }
  195.