home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_Except_il________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-08-21  |  7.6 KB  |  199 lines

  1. //=====================================================================
  2. //  File:      Except.il
  3. //
  4. //  Summary:   Demonstrates how to use exceptions
  5. //
  6. //---------------------------------------------------------------------
  7. //  This file is part of the Microsoft .NET SDK Code Samples.
  8. //
  9. //  Copyright (C) Microsoft Corporation.  All rights reserved.
  10. //
  11. //This source code is intended only as a supplement to Microsoft
  12. //Development Tools and/or on-line documentation.  See these other
  13. //materials for detailed information regarding Microsoft code samples.
  14. //
  15. //THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  16. //KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. //IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  18. //PARTICULAR PURPOSE.
  19. //=====================================================================
  20.  
  21. //This source was created using IlDasm.exe
  22.  
  23. .assembly extern mscorlib
  24. {
  25. }
  26.  
  27. .assembly extern System.Windows.Forms
  28. {
  29. }
  30.  
  31. .assembly Except
  32. {
  33. }
  34.  
  35. .class private auto ansi beforefieldinit App
  36.        extends [mscorlib]System.Object
  37. {
  38.   .method public hidebysig static void  Main() cil managed
  39.   {
  40.     .entrypoint
  41.     // Code size       82 (0x52)
  42.     .maxstack  4
  43.     IL_0000:  call       class [mscorlib]System.AppDomain [mscorlib]System.Threading.Thread::GetDomain()
  44.     IL_0005:  ldnull
  45.     IL_0006:  ldftn      void App::HandleUnhandled(object,
  46.                                                    class [mscorlib]System.UnhandledExceptionEventArgs)
  47.     IL_000c:  newobj     instance void [mscorlib]System.UnhandledExceptionEventHandler::.ctor(object,
  48.                                                                                               native int)
  49.     IL_0011:  callvirt   instance void [mscorlib]System.AppDomain::add_UnhandledException(class [mscorlib]System.UnhandledExceptionEventHandler)
  50.     IL_0016:  ldc.i4.1
  51.     IL_0017:  call       void App::ProtectedFunction(int32)
  52.     IL_001c:  call       void [mscorlib]System.Console::WriteLine()
  53.     IL_0021:  ldc.i4.2
  54.     IL_0022:  call       void App::ProtectedFunction(int32)
  55.     IL_0027:  call       void [mscorlib]System.Console::WriteLine()
  56.     IL_002c:  ldc.i4.3
  57.     IL_002d:  call       void App::ProtectedFunction(int32)
  58.     IL_0032:  call       void [mscorlib]System.Console::WriteLine()
  59.     IL_0037:  ldstr      "Just about to execute code that throws an unhandle"
  60.     + "d exception:"
  61.     IL_003c:  call       void [mscorlib]System.Console::WriteLine(string)
  62.     IL_0041:  ldc.i4.1
  63.     IL_0042:  call       void App::MethodThatThrows(int32)
  64.     IL_0047:  ldstr      "This code never executes!"
  65.     IL_004c:  call       void [mscorlib]System.Console::WriteLine(string)
  66.     IL_0051:  ret
  67.   } // end of method App::Main
  68.  
  69.   .method private hidebysig static void  MethodThatThrows(int32 option) cil managed
  70.   {
  71.     // Code size       60 (0x3c)
  72.     .maxstack  2
  73.     .locals init ([0] int32 x,
  74.              [1] object o,
  75.              [2] int32 CS$00000002$00000000)
  76.     IL_0000:  ldarg.0
  77.     IL_0001:  stloc.2
  78.     IL_0002:  ldloc.2
  79.     IL_0003:  ldc.i4.1
  80.     IL_0004:  sub
  81.     IL_0005:  switch     ( 
  82.                           IL_0018,
  83.                           IL_0021,
  84.                           IL_0030)
  85.     IL_0016:  br.s       IL_003b
  86.  
  87.     IL_0018:  ldc.i4.0
  88.     IL_0019:  stloc.0
  89.     IL_001a:  ldc.i4.s   10
  90.     IL_001c:  ldloc.0
  91.     IL_001d:  div
  92.     IL_001e:  stloc.0
  93.     IL_001f:  br.s       IL_003b
  94.  
  95.     IL_0021:  ldnull
  96.     IL_0022:  stloc.1
  97.     IL_0023:  ldloc.1
  98.     IL_0024:  callvirt   instance string [mscorlib]System.Object::ToString()
  99.     IL_0029:  call       void [mscorlib]System.Console::WriteLine(string)
  100.     IL_002e:  br.s       IL_003b
  101.  
  102.     IL_0030:  ldstr      "This is a custom exception"
  103.     IL_0035:  newobj     instance void MyException::.ctor(string)
  104.     IL_003a:  throw
  105.  
  106.     IL_003b:  ret
  107.   } // end of method App::MethodThatThrows
  108.  
  109.   .method private hidebysig static void  ProtectedFunction(int32 option) cil managed
  110.   {
  111.     // Code size       81 (0x51)
  112.     .maxstack  3
  113.     .locals init ([0] class [mscorlib]System.Exception e)
  114.     .try
  115.     {
  116.       IL_0000:  ldarg.0
  117.       IL_0001:  call       void App::MethodThatThrows(int32)
  118.       IL_0006:  leave.s    IL_0050
  119.  
  120.     }  // end .try
  121.     catch [mscorlib]System.Exception 
  122.     {
  123.       IL_0008:  stloc.0
  124.       IL_0009:  ldstr      "Exception:\n   {0}"
  125.       IL_000e:  ldloc.0
  126.       IL_000f:  callvirt   instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
  127.       IL_0014:  callvirt   instance string [mscorlib]System.Type::ToString()
  128.       IL_0019:  call       void [mscorlib]System.Console::WriteLine(string,
  129.                                                                     object)
  130.       IL_001e:  ldstr      "Message:\n   {0}"
  131.       IL_0023:  ldloc.0
  132.       IL_0024:  callvirt   instance string [mscorlib]System.Exception::get_Message()
  133.       IL_0029:  call       void [mscorlib]System.Console::WriteLine(string,
  134.                                                                     object)
  135.       IL_002e:  ldstr      "Stack Trace:\n{0}"
  136.       IL_0033:  ldloc.0
  137.       IL_0034:  callvirt   instance string [mscorlib]System.Exception::get_StackTrace()
  138.       IL_0039:  call       void [mscorlib]System.Console::WriteLine(string,
  139.                                                                     object)
  140.       IL_003e:  ldstr      "Help Link:\n   {0}"
  141.       IL_0043:  ldloc.0
  142.       IL_0044:  callvirt   instance string [mscorlib]System.Exception::get_HelpLink()
  143.       IL_0049:  call       void [mscorlib]System.Console::WriteLine(string,
  144.                                                                     object)
  145.       IL_004e:  leave.s    IL_0050
  146.  
  147.     }  // end handler
  148.     IL_0050:  ret
  149.   } // end of method App::ProtectedFunction
  150.  
  151.   .method public hidebysig static void  HandleUnhandled(object sender,
  152.                                                         class [mscorlib]System.UnhandledExceptionEventArgs args) cil managed
  153.   {
  154.     // Code size       38 (0x26)
  155.     .maxstack  3
  156.     IL_0000:  ldstr      "Unhandled Exception!\n"
  157.     IL_0005:  ldarg.1
  158.     IL_0006:  callvirt   instance object [mscorlib]System.UnhandledExceptionEventArgs::get_ExceptionObject()
  159.     IL_000b:  callvirt   instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
  160.     IL_0010:  callvirt   instance string [mscorlib]System.Type::ToString()
  161.     IL_0015:  call       string [mscorlib]System.String::Concat(string,
  162.                                                                 string)
  163.     IL_0024:  call       void [mscorlib]System.Console::WriteLine(string)
  164.     IL_0025:  ret
  165.   } // end of method App::HandleUnhandled
  166.  
  167.   .method public hidebysig specialname rtspecialname 
  168.           instance void  .ctor() cil managed
  169.   {
  170.     // Code size       7 (0x7)
  171.     .maxstack  1
  172.     IL_0000:  ldarg.0
  173.     IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
  174.     IL_0006:  ret
  175.   } // end of method App::.ctor
  176.  
  177. } // end of class App
  178.  
  179. .class private auto ansi beforefieldinit MyException
  180.        extends [mscorlib]System.ApplicationException
  181. {
  182.   .method public hidebysig specialname rtspecialname 
  183.           instance void  .ctor(string msg) cil managed
  184.   {
  185.     // Code size       19 (0x13)
  186.     .maxstack  2
  187.     IL_0000:  ldarg.0
  188.     IL_0001:  ldarg.1
  189.     IL_0002:  call       instance void [mscorlib]System.ApplicationException::.ctor(string)
  190.     IL_0007:  ldarg.0
  191.     IL_0008:  ldstr      "http://NotARealURL.Microsoft.com/help.html"
  192.     IL_000d:  callvirt   instance void [mscorlib]System.Exception::set_HelpLink(string)
  193.     IL_0012:  ret
  194.   } // end of method MyException::.ctor
  195.  
  196. } // end of class MyException
  197.  
  198.  
  199.