<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLanguage_Basics%2FException</id>
		<title>Csharp/CSharp Tutorial/Language Basics/Exception - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FLanguage_Basics%2FException"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/Exception&amp;action=history"/>
		<updated>2026-04-29T17:29:16Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/Exception&amp;diff=6540&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/Exception&amp;diff=6540&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/Exception&amp;diff=6541&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Language_Basics/Exception&amp;diff=6541&amp;oldid=prev"/>
				<updated>2010-05-26T12:19:21Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A Closer Look at Exception==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Message property contains a string that describes the nature of the error.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;StackTrace property contains a string that contains the stack of calls that lead to the exception.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;TargetSite property obtains an object that specifies the method that generated the exception.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;System.Exception also defines several methods.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;ToString() returns a string that describes the exception.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Exception defines four constructors.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The most commonly used are shown here:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;Exception()&lt;br /&gt;
  Exception(string str)&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==An unhandled exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    int[] myArray = new int[2];&lt;br /&gt;
    Console.WriteLine(&amp;quot;Attempting to access an invalid array element&amp;quot;);&lt;br /&gt;
    myArray[2] = 1;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Attempting to access an invalid array element&lt;br /&gt;
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.&lt;br /&gt;
   at MainClass.Main()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Commonly Used Exceptions Defined Within the System Namespace ==&lt;br /&gt;
&lt;br /&gt;
Exception&lt;br /&gt;
Meaning&lt;br /&gt;
ArrayTypeMismatchException&lt;br /&gt;
Type is incompatible with the type of the array.&lt;br /&gt;
DivideByZeroException&lt;br /&gt;
Division by zero attempted.&lt;br /&gt;
IndexOutOfRangeException&lt;br /&gt;
Array index is out of bounds.&lt;br /&gt;
InvalidCastException&lt;br /&gt;
A runtime cast is invalid.&lt;br /&gt;
OutOfMemoryException&lt;br /&gt;
Insufficient free memory exists.&lt;br /&gt;
OverflowException&lt;br /&gt;
An arithmetic overflow occurred.&lt;br /&gt;
NullReferenceException&lt;br /&gt;
An attempt was made to operate on a null reference�that is, a reference that does not refer to an object.&lt;br /&gt;
StackOverflowException&lt;br /&gt;
The stack was Overflow.&lt;br /&gt;
&amp;lt;p&amp;gt;As a general rule, exceptions defined by you should be derived from ApplicationException since this is the&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;hierarchy reserved for application- related exceptions.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Exception propagation with methods==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    Console.WriteLine(&amp;quot;Calling AccessInvalidArrayElement()&amp;quot;);&lt;br /&gt;
    AccessInvalidArrayElement();&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Calling DivideByZero()&amp;quot;);&lt;br /&gt;
      DivideByZero();&lt;br /&gt;
    } catch (DivideByZeroException e) {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Handling an IndexOutOfRangeException&amp;quot;);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Message = &amp;quot; + e.Message);&lt;br /&gt;
      Console.WriteLine(&amp;quot;StackTrace = &amp;quot; + e.StackTrace);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void AccessInvalidArrayElement()&lt;br /&gt;
  {&lt;br /&gt;
    int[] myArray = new int[2];&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Attempting to access an invalid array element&amp;quot;);&lt;br /&gt;
      myArray[20] = 1;&lt;br /&gt;
    }&lt;br /&gt;
    catch (IndexOutOfRangeException e)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(&amp;quot;Handling an IndexOutOfRangeException&amp;quot;);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Message = &amp;quot; + e.Message);&lt;br /&gt;
      Console.WriteLine(&amp;quot;StackTrace = &amp;quot; + e.StackTrace);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void DivideByZero()&lt;br /&gt;
  {&lt;br /&gt;
    int zero = 0;&lt;br /&gt;
    Console.WriteLine(&amp;quot;Attempting division by zero&amp;quot;);&lt;br /&gt;
    int myInt = 1 / zero;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Calling AccessInvalidArrayElement()&lt;br /&gt;
Attempting to access an invalid array element&lt;br /&gt;
Handling an IndexOutOfRangeException&lt;br /&gt;
Message = Index was outside the bounds of the array.&lt;br /&gt;
StackTrace =    at MainClass.AccessInvalidArrayElement()&lt;br /&gt;
Calling DivideByZero()&lt;br /&gt;
Attempting division by zero&lt;br /&gt;
Handling an IndexOutOfRangeException&lt;br /&gt;
Message = Attempted to divide by zero.&lt;br /&gt;
StackTrace =    at MainClass.Main()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Handling a possible exception.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static int AnExceptionFunction(int value) {&lt;br /&gt;
        if (value == 0) // Can&amp;quot;t divide by zero&lt;br /&gt;
            throw new DivideByZeroException(&amp;quot;Divide By 0 error!&amp;quot;);&lt;br /&gt;
        int x = 20 / value;&lt;br /&gt;
        return x;&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        int value = 0;&lt;br /&gt;
        try {&lt;br /&gt;
            value = AnExceptionFunction(10); // This works ok&lt;br /&gt;
            Console.WriteLine(&amp;quot;Value = {0}&amp;quot;, value);&lt;br /&gt;
            AnExceptionFunction(0); // This doesn&amp;quot;t&lt;br /&gt;
            Console.WriteLine(&amp;quot;Value = {0}&amp;quot;, value);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Caught an exception {0}. Continuing&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;Done&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Exception Hierarchy==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An exception is an error that occurs at runtime.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
class MainClass{&lt;br /&gt;
    &lt;br /&gt;
    public static void Main(){&lt;br /&gt;
        int Zero = 0;&lt;br /&gt;
        try {&lt;br /&gt;
            int j = 22 / Zero;&lt;br /&gt;
        } catch (DivideByZeroException e) // catch a specific exception&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;DivideByZero {0}&amp;quot;, e);&lt;br /&gt;
        } catch (Exception e)// catch any remaining exceptions&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Exception {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;DivideByZero System.DivideByZeroException: Attempted to divide by zero.&lt;br /&gt;
   at MainClass.Main()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The System.Exception Class==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;In C#, exceptions are represented by classes.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;All exception classes must be derived from the built-in exception class System.Exception.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;SystemException class and ApplicationException class are derived from System.Exception.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;SystemException support exceptions generated by the C# runtime system (that is, the Common Language Runtime)&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;ApplicationException support exceptions generated by application programs.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;SystemException and ApplicationException add nothing to Exception.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;SystemException and ApplicationException define the tops of two different exception hierarchies.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
1.17.Exception&lt;br /&gt;
1.17.1.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/TheExceptionHierarchy.htm&amp;quot;&amp;gt;The Exception Hierarchy&amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.2.&lt;br /&gt;
The System.Exception Class&lt;br /&gt;
1.17.3.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/ACloserLookatException.htm&amp;quot;&amp;gt;A Closer Look at Exception&amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.4.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/UsingExceptionmembers.htm&amp;quot;&amp;gt;Using Exception members&amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.5.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/Exceptionpropagationwithmethods.htm&amp;quot;&amp;gt;Exception propagation with methods&amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.6.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/Anunhandledexception.htm&amp;quot;&amp;gt;An unhandled exception&amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.7.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/CommonlyUsedExceptionsDefinedWithintheSystemNamespace.htm&amp;quot;&amp;gt;Commonly Used Exceptions Defined Within the System Namespace &amp;lt;/a&amp;gt;&lt;br /&gt;
1.17.8.&lt;br /&gt;
&amp;lt;A href=&amp;quot;/Tutorial/CSharp/0020__Language-Basics/Handlingapossibleexception.htm&amp;quot;&amp;gt;Handling a possible exception.&amp;lt;/a&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using Exception members==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System; &lt;br /&gt;
 &lt;br /&gt;
class MainClass {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
  &lt;br /&gt;
    try {  &lt;br /&gt;
        int[] nums = new int[4];  &lt;br /&gt;
     &lt;br /&gt;
        Console.WriteLine(&amp;quot;Before exception is generated.&amp;quot;); &lt;br /&gt;
     &lt;br /&gt;
        // Generate an index out-of-bounds exception. &lt;br /&gt;
        for(int i=0; i &amp;lt; 10; i++) { &lt;br /&gt;
            nums[i] = i; &lt;br /&gt;
        } &lt;br /&gt;
    }  &lt;br /&gt;
    catch (IndexOutOfRangeException exc) {  &lt;br /&gt;
      Console.WriteLine(&amp;quot;Standard message is: &amp;quot;); &lt;br /&gt;
      Console.WriteLine(exc); // calls ToString() &lt;br /&gt;
      Console.WriteLine(&amp;quot;Stack trace: &amp;quot; + exc.StackTrace); &lt;br /&gt;
      Console.WriteLine(&amp;quot;Message: &amp;quot; + exc.Message); &lt;br /&gt;
      Console.WriteLine(&amp;quot;TargetSite: &amp;quot; + exc.TargetSite); &lt;br /&gt;
      Console.WriteLine(&amp;quot;Class defining member: {0}&amp;quot;, exc.TargetSite.DeclaringType);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Member type: {0}&amp;quot;, exc.TargetSite.MemberType);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Source: {0}&amp;quot;, exc.Source);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Help Link: {0}&amp;quot;, exc.HelpLink);&lt;br /&gt;
      &lt;br /&gt;
    }  &lt;br /&gt;
    Console.WriteLine(&amp;quot;After catch statement.&amp;quot;);  &lt;br /&gt;
  }  &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Before exception is generated.&lt;br /&gt;
Standard message is:&lt;br /&gt;
System.IndexOutOfRangeException: Index was outside the bounds of the array.&lt;br /&gt;
   at MainClass.Main()&lt;br /&gt;
Stack trace:    at MainClass.Main()&lt;br /&gt;
Message: Index was outside the bounds of the array.&lt;br /&gt;
TargetSite: Void Main()&lt;br /&gt;
Class defining member: MainClass&lt;br /&gt;
Member type: Method&lt;br /&gt;
Source: main&lt;br /&gt;
Help Link:&lt;br /&gt;
After catch statement.&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>