<?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%2FC_Sharp%2FLanguage_Basics%2FException_Class</id>
		<title>Csharp/C Sharp/Language Basics/Exception Class - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FLanguage_Basics%2FException_Class"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Language_Basics/Exception_Class&amp;action=history"/>
		<updated>2026-04-30T02:51:10Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Language_Basics/Exception_Class&amp;diff=680&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Language_Basics/Exception_Class&amp;diff=680&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</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/C_Sharp/Language_Basics/Exception_Class&amp;diff=681&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Language_Basics/Exception_Class&amp;diff=681&amp;oldid=prev"/>
				<updated>2010-05-26T11:39:28Z</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;==calls GetBaseException and outputs the error message of the initial exception.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
public class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        try {&lt;br /&gt;
            MethodA();&lt;br /&gt;
        } catch (Exception except) {&lt;br /&gt;
            Exception original = except.GetBaseException();&lt;br /&gt;
            Console.WriteLine(original.Message);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void MethodA() {&lt;br /&gt;
        try {&lt;br /&gt;
            MethodB();&lt;br /&gt;
        } catch (Exception except) {&lt;br /&gt;
            throw new ApplicationException(&amp;quot;Inner Exception&amp;quot;, except);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void MethodB() {&lt;br /&gt;
        throw new ApplicationException(&amp;quot;Innermost Exception&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Demonstrates defining and using a custom exception class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
//&lt;br /&gt;
// CustExcp.cs -- Demonstrates defining and using a custom exception class&lt;br /&gt;
//&lt;br /&gt;
//                Compile this program with the following command line:&lt;br /&gt;
//                    C:&amp;gt;csc CustExcp.cs&lt;br /&gt;
//&lt;br /&gt;
namespace nsCustomException&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    using System.IO;&lt;br /&gt;
    &lt;br /&gt;
    public class CustExcpclsMain&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main (string [] args)&lt;br /&gt;
        {&lt;br /&gt;
            if (args.Length &amp;lt; 2)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;usage: CustExcp FileName String&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                ReadFile (args[0], args[1]);&lt;br /&gt;
                Console.WriteLine (args[1] + &amp;quot; was not found in &amp;quot; + args[0]);&lt;br /&gt;
            }&lt;br /&gt;
// Custom exception thrown. Display the information.&lt;br /&gt;
            catch (clsException e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;string {0} first occurs in {1} at Line {2}, Column {3}&amp;quot;,&lt;br /&gt;
                                   args[1], args[0], e.Line, e.Column);&lt;br /&gt;
                Console.WriteLine (e.Found);&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
// Check for other possible exceptions.&lt;br /&gt;
            catch (ArgumentException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;The file name &amp;quot; + args [0] +&lt;br /&gt;
                          &amp;quot; is empty or contains an invalid character&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch (FileNotFoundException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;The file name &amp;quot; + args [0] +&lt;br /&gt;
                                   &amp;quot; cannot be found&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch (DirectoryNotFoundException)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (&amp;quot;The path for &amp;quot; + args [0] +&lt;br /&gt;
                                   &amp;quot; is invalid&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception e)&lt;br /&gt;
            {&lt;br /&gt;
                Console.WriteLine (e);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        static public void ReadFile (string FileName, string Find)&lt;br /&gt;
        {&lt;br /&gt;
            FileStream strm;&lt;br /&gt;
            StreamReader reader;&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                strm = new FileStream (FileName, FileMode.Open);&lt;br /&gt;
                reader = new StreamReader (strm);&lt;br /&gt;
                int Line = 0;&lt;br /&gt;
                while (reader.Peek () &amp;gt;= 0)&lt;br /&gt;
                {&lt;br /&gt;
                    ++Line;&lt;br /&gt;
                    string str = reader.ReadLine ();&lt;br /&gt;
                    int index = str.IndexOf (Find);&lt;br /&gt;
                    if (index &amp;gt;= 0)&lt;br /&gt;
                    {&lt;br /&gt;
                        reader.Close ();&lt;br /&gt;
                        strm.Close ();&lt;br /&gt;
                        clsException ex = new clsException ();&lt;br /&gt;
                        ex.Line = Line;&lt;br /&gt;
                        ex.Column = index + 1;&lt;br /&gt;
                        ex.Found = str;&lt;br /&gt;
                        throw (ex);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                reader.Close ();&lt;br /&gt;
                strm.Close ();&lt;br /&gt;
                return;&lt;br /&gt;
            }&lt;br /&gt;
            catch (IOException e)&lt;br /&gt;
            {&lt;br /&gt;
// If file not found, go back and get another name&lt;br /&gt;
                if (e is FileNotFoundException)&lt;br /&gt;
                    throw (e);&lt;br /&gt;
// Code here to handle other IOException classes&lt;br /&gt;
                Console.WriteLine (e.Message);&lt;br /&gt;
                throw (new IOException());&lt;br /&gt;
            }&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
// Define a class derived from Exception&lt;br /&gt;
    class clsException : Exception&lt;br /&gt;
    {&lt;br /&gt;
        public int Line = 0;&lt;br /&gt;
        public int Column = 0;&lt;br /&gt;
        public string Found = null;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Derived exceptions must appear before base class exceptions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Derived exceptions must appear before base class exceptions. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
// Create an exception. &lt;br /&gt;
class ExceptA : ApplicationException { &lt;br /&gt;
  public ExceptA() : base() { } &lt;br /&gt;
  public ExceptA(string str) : base(str) { } &lt;br /&gt;
 &lt;br /&gt;
  public override string ToString() { &lt;br /&gt;
    return Message; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// Create an exception derived from ExceptA &lt;br /&gt;
class ExceptB : ExceptA { &lt;br /&gt;
  public ExceptB() : base() { } &lt;br /&gt;
  public ExceptB(string str) : base(str) { } &lt;br /&gt;
 &lt;br /&gt;
  public override string ToString() { &lt;br /&gt;
    return Message;  &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
public class OrderMatters { &lt;br /&gt;
  public static void Main() { &lt;br /&gt;
    for(int x = 0; x &amp;lt; 3; x++) { &lt;br /&gt;
      try { &lt;br /&gt;
        if(x==0) throw new ExceptA(&amp;quot;Caught an ExceptA exception&amp;quot;); &lt;br /&gt;
        else if(x==1) throw new ExceptB(&amp;quot;Caught an ExceptB exception&amp;quot;); &lt;br /&gt;
        else throw new Exception(); &lt;br /&gt;
      } &lt;br /&gt;
      catch (ExceptB exc) { &lt;br /&gt;
        // catch the exception &lt;br /&gt;
        Console.WriteLine(exc); &lt;br /&gt;
      } &lt;br /&gt;
      catch (ExceptA exc) { &lt;br /&gt;
        // catch the exception &lt;br /&gt;
        Console.WriteLine(exc); &lt;br /&gt;
      } &lt;br /&gt;
      catch (Exception exc) { &lt;br /&gt;
        Console.WriteLine(exc); &lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exception handle with your own exception class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Learning C# &lt;br /&gt;
by Jesse Liberty&lt;br /&gt;
Publisher: O&amp;quot;Reilly &lt;br /&gt;
ISBN: 0596003765&lt;br /&gt;
*/&lt;br /&gt;
 using System;&lt;br /&gt;
 namespace ExceptionHandling&lt;br /&gt;
 {&lt;br /&gt;
     // custom exception class&lt;br /&gt;
     class MyCustomException :&lt;br /&gt;
         System.ApplicationException&lt;br /&gt;
     {&lt;br /&gt;
         public MyCustomException(string message):&lt;br /&gt;
             base(message) // pass the message up to the base class&lt;br /&gt;
         {&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
    public class TesterExceptionHandling&lt;br /&gt;
    {&lt;br /&gt;
       public void Run()&lt;br /&gt;
       {&lt;br /&gt;
           try&lt;br /&gt;
           {&lt;br /&gt;
               Console.WriteLine(&amp;quot;Open file here&amp;quot;);&lt;br /&gt;
               double a = 0;&lt;br /&gt;
               double b = 5;&lt;br /&gt;
               Console.WriteLine (&amp;quot;{0} / {1} = {2}&amp;quot;,&lt;br /&gt;
                   a, b, DoDivide(a,b));&lt;br /&gt;
               Console.WriteLine (&lt;br /&gt;
                   &amp;quot;This line may or may not print&amp;quot;);&lt;br /&gt;
           }&lt;br /&gt;
               // most derived exception type first&lt;br /&gt;
           catch (System.DivideByZeroException e)&lt;br /&gt;
           {&lt;br /&gt;
               Console.WriteLine(&lt;br /&gt;
                   &amp;quot;\nDivideByZeroException! Msg: {0}&amp;quot;,&lt;br /&gt;
                   e.Message);&lt;br /&gt;
               Console.WriteLine(&lt;br /&gt;
                   &amp;quot;\nHelpLink: {0}\n&amp;quot;, e.HelpLink);&lt;br /&gt;
           }&lt;br /&gt;
           // catch custom exception&lt;br /&gt;
           catch (MyCustomException e)&lt;br /&gt;
           {&lt;br /&gt;
               Console.WriteLine(&lt;br /&gt;
                   &amp;quot;\nMyCustomException! Msg: {0}&amp;quot;,&lt;br /&gt;
                   e.Message);&lt;br /&gt;
               Console.WriteLine(&lt;br /&gt;
                   &amp;quot;\nHelpLink: {0}\n&amp;quot;, e.HelpLink);&lt;br /&gt;
           }&lt;br /&gt;
           catch     // catch any uncaught exceptions&lt;br /&gt;
           {&lt;br /&gt;
               Console.WriteLine(&lt;br /&gt;
                   &amp;quot;Unknown exception caught&amp;quot;);&lt;br /&gt;
           }&lt;br /&gt;
           finally&lt;br /&gt;
           {&lt;br /&gt;
               Console.WriteLine (&amp;quot;Close file here.&amp;quot;);&lt;br /&gt;
           }&lt;br /&gt;
       }&lt;br /&gt;
        // do the division if legal&lt;br /&gt;
        public double DoDivide(double a, double b)&lt;br /&gt;
        {&lt;br /&gt;
            if (b == 0)&lt;br /&gt;
            {&lt;br /&gt;
                DivideByZeroException e =&lt;br /&gt;
                    new DivideByZeroException();&lt;br /&gt;
                e.HelpLink=&lt;br /&gt;
                    &amp;quot;http://www.libertyassociates.ru&amp;quot;;&lt;br /&gt;
                throw e;&lt;br /&gt;
            }&lt;br /&gt;
            if (a == 0)&lt;br /&gt;
            {&lt;br /&gt;
                // create a custom exception instance&lt;br /&gt;
                MyCustomException e =&lt;br /&gt;
                    new MyCustomException(&lt;br /&gt;
                    &amp;quot;Can&amp;quot;t have zero divisor&amp;quot;);&lt;br /&gt;
                e.HelpLink =&lt;br /&gt;
                    &amp;quot;http://www.libertyassociates.ru/NoZeroDivisor.htm&amp;quot;;&lt;br /&gt;
                throw e;&lt;br /&gt;
            }&lt;br /&gt;
            return a/b;&lt;br /&gt;
        }&lt;br /&gt;
        static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Enter Main...&amp;quot;);&lt;br /&gt;
            TesterExceptionHandling t = new TesterExceptionHandling();&lt;br /&gt;
            t.Run();&lt;br /&gt;
            Console.WriteLine(&amp;quot;Exit Main...&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exception Handling: The Exception Hierarchy 1==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
public class ExceptionHierarchy&lt;br /&gt;
{&lt;br /&gt;
    static int Zero = 0;&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            int j = 22 / Zero;&lt;br /&gt;
        }&lt;br /&gt;
        // catch a specific exception&lt;br /&gt;
        catch (DivideByZeroException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;DivideByZero {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
        // catch any remaining exceptions&lt;br /&gt;
        catch (Exception e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Exception {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exception Handling: The Exception Hierarchy 2==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
public class ExceptionHierarchyNeverExecuted&lt;br /&gt;
{&lt;br /&gt;
    static int Zero = 0;&lt;br /&gt;
    static void AFunction()&lt;br /&gt;
    {&lt;br /&gt;
        int j = 22 / Zero;&lt;br /&gt;
        Console.WriteLine(&amp;quot;In AFunction()&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            AFunction();&lt;br /&gt;
        }&lt;br /&gt;
        catch (DivideByZeroException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;DivideByZero {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exception Handling: The Exception Hierarchy 3==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
public class ExceptionHierarchyOutOfRangeException&lt;br /&gt;
{&lt;br /&gt;
    static int Zero = 0;&lt;br /&gt;
    static void AFunction()&lt;br /&gt;
    {&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            int j = 22 / Zero;&lt;br /&gt;
        }&lt;br /&gt;
       // this exception doesn&amp;quot;t match&lt;br /&gt;
        catch (ArgumentOutOfRangeException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;OutOfRangeException: {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
        Console.WriteLine(&amp;quot;In AFunction()&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            AFunction();&lt;br /&gt;
        }&lt;br /&gt;
        // this exception doesn&amp;quot;t match&lt;br /&gt;
        catch (ArgumentException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;ArgumentException {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exception Handling User-Defined Exception Classes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 04 - Exception Handling\User-Defined Exception Classes&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
public class UserDefinedExceptionClasses&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Summer summer = new Summer();&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            summer.DoAverage();&lt;br /&gt;
        }&lt;br /&gt;
        catch (CountIsZeroException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;CountIsZeroException: {0}&amp;quot;, e);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class CountIsZeroException: ApplicationException&lt;br /&gt;
{&lt;br /&gt;
    public CountIsZeroException()&lt;br /&gt;
    {&lt;br /&gt;
    }&lt;br /&gt;
    public CountIsZeroException(string message)&lt;br /&gt;
    : base(message)&lt;br /&gt;
    {&lt;br /&gt;
    }&lt;br /&gt;
    public CountIsZeroException(string message, Exception inner)&lt;br /&gt;
    : base(message, inner)&lt;br /&gt;
    {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Summer&lt;br /&gt;
{&lt;br /&gt;
    int    sum = 0;&lt;br /&gt;
    int    count = 0;&lt;br /&gt;
    float    average;&lt;br /&gt;
    public void DoAverage()&lt;br /&gt;
    {&lt;br /&gt;
        if (count == 0)&lt;br /&gt;
        throw(new CountIsZeroException(&amp;quot;Zero count in DoAverage&amp;quot;));&lt;br /&gt;
        else&lt;br /&gt;
        average = sum / count;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates a custom exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example13_9.cs illustrates a custom exception&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
// declare the CustomException class&lt;br /&gt;
class CustomException : ApplicationException&lt;br /&gt;
{&lt;br /&gt;
  public CustomException(string Message) : base(Message)&lt;br /&gt;
  {&lt;br /&gt;
    // set the HelpLink and Source properties&lt;br /&gt;
    this.HelpLink = &amp;quot;See the Readme.txt file&amp;quot;;&lt;br /&gt;
    this.Source = &amp;quot;My Example13_9 Program&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example13_9&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
      // throw a new CustomException object&lt;br /&gt;
      Console.WriteLine(&amp;quot;Throwing a new CustomException object&amp;quot;);&lt;br /&gt;
      throw new CustomException(&amp;quot;My CustomException message&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    catch (CustomException e)&lt;br /&gt;
    {&lt;br /&gt;
      // display the CustomException object&amp;quot;s properties&lt;br /&gt;
      Console.WriteLine(&amp;quot;HelpLink = &amp;quot; + e.HelpLink);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Message = &amp;quot; + e.Message);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Source = &amp;quot; + e.Source);&lt;br /&gt;
      Console.WriteLine(&amp;quot;StackTrace = &amp;quot; + e.StackTrace);&lt;br /&gt;
      Console.WriteLine(&amp;quot;TargetSite = &amp;quot; + e.TargetSite);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==illustrates the use of a System.Exception object==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example13_2.cs illustrates the use of a&lt;br /&gt;
  System.Exception object&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
public class Example13_2&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
      int zero = 0;&lt;br /&gt;
      Console.WriteLine(&amp;quot;In try block: attempting division by zero&amp;quot;);&lt;br /&gt;
      int myInt = 1 / zero;  // throws the exception&lt;br /&gt;
    }&lt;br /&gt;
    catch (System.Exception myException)&lt;br /&gt;
    {&lt;br /&gt;
      // display the exception object&amp;quot;s properties&lt;br /&gt;
      Console.WriteLine(&amp;quot;HelpLink = &amp;quot; + myException.HelpLink);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Message = &amp;quot; + myException.Message);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Source = &amp;quot; + myException.Source);&lt;br /&gt;
      Console.WriteLine(&amp;quot;StackTrace = &amp;quot; + myException.StackTrace);&lt;br /&gt;
      Console.WriteLine(&amp;quot;TargetSite = &amp;quot; + myException.TargetSite);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==refines the System.Exception base class with name of the type and time of exception to create your own Exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
public class ConstructorException : Exception {&lt;br /&gt;
    public ConstructorException(object origin)&lt;br /&gt;
        : this(origin, null) {&lt;br /&gt;
    }&lt;br /&gt;
    public ConstructorException(object origin, Exception innerException)&lt;br /&gt;
        : base(&amp;quot;Exception in constructor&amp;quot;, innerException) {&lt;br /&gt;
        prop_Typename = origin.GetType().Name;&lt;br /&gt;
        prop_Time = DateTime.Now.ToLongDateString() + &amp;quot; &amp;quot; +&lt;br /&gt;
            DateTime.Now.ToShortTimeString();&lt;br /&gt;
    }&lt;br /&gt;
    protected string prop_Typename = null;&lt;br /&gt;
    public string Typename {&lt;br /&gt;
        get {&lt;br /&gt;
            return prop_Typename;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    protected string prop_Time = null;&lt;br /&gt;
    public string Time {&lt;br /&gt;
        get {&lt;br /&gt;
            return prop_Time;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        try {&lt;br /&gt;
            MyClass obj = new MyClass();&lt;br /&gt;
        } catch (ConstructorException except) {&lt;br /&gt;
            Console.WriteLine(except.Message);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Typename: &amp;quot; + except.Typename);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Occured: &amp;quot; + except.Time);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class MyClass {&lt;br /&gt;
    public MyClass() {&lt;br /&gt;
        // initialization fails&lt;br /&gt;
        throw new ConstructorException(this);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use a custom Exception for RangeArray errors==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Use a custom Exception for RangeArray errors. &lt;br /&gt;
  &lt;br /&gt;
using System;  &lt;br /&gt;
  &lt;br /&gt;
// Create an RangeArray exception. &lt;br /&gt;
class RangeArrayException : ApplicationException { &lt;br /&gt;
  // Implement the standard constructors &lt;br /&gt;
  public RangeArrayException() : base() { } &lt;br /&gt;
  public RangeArrayException(string str) : base(str) { }  &lt;br /&gt;
 &lt;br /&gt;
  // Override ToString for RangeArrayException. &lt;br /&gt;
  public override string ToString() { &lt;br /&gt;
    return Message; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
// An improved version of RangeArray. &lt;br /&gt;
class RangeArray {   &lt;br /&gt;
  // private data &lt;br /&gt;
  int[] a; // reference to underlying array   &lt;br /&gt;
  int lowerBound; // lowest index &lt;br /&gt;
  int upperBound; // greatest index &lt;br /&gt;
 &lt;br /&gt;
  int len; // underlying var for Length property &lt;br /&gt;
    &lt;br /&gt;
  // Construct array given its size.  &lt;br /&gt;
  public RangeArray(int low, int high) {  &lt;br /&gt;
    high++; &lt;br /&gt;
    if(high &amp;lt;= low) { &lt;br /&gt;
      throw new RangeArrayException(&amp;quot;Low index not less than high.&amp;quot;); &lt;br /&gt;
    } &lt;br /&gt;
    a = new int[high - low];  &lt;br /&gt;
    len = high - low;   &lt;br /&gt;
 &lt;br /&gt;
    lowerBound = low; &lt;br /&gt;
    upperBound = --high; &lt;br /&gt;
  }  &lt;br /&gt;
  &lt;br /&gt;
  // Read-only Length property.  &lt;br /&gt;
  public int Length {  &lt;br /&gt;
    get {  &lt;br /&gt;
      return len;  &lt;br /&gt;
    }  &lt;br /&gt;
  }  &lt;br /&gt;
 &lt;br /&gt;
  // This is the indexer for RangeArray.  &lt;br /&gt;
  public int this[int index] {  &lt;br /&gt;
    // This is the get accessor.  &lt;br /&gt;
    get {  &lt;br /&gt;
      if(ok(index)) {  &lt;br /&gt;
        return a[index - lowerBound];  &lt;br /&gt;
      } else {  &lt;br /&gt;
        throw new RangeArrayException(&amp;quot;Range Error.&amp;quot;); &lt;br /&gt;
      } &lt;br /&gt;
    }  &lt;br /&gt;
  &lt;br /&gt;
    // This is the set accessor. &lt;br /&gt;
    set {  &lt;br /&gt;
      if(ok(index)) {  &lt;br /&gt;
        a[index - lowerBound] = value;  &lt;br /&gt;
      }  &lt;br /&gt;
      else throw new RangeArrayException(&amp;quot;Range Error.&amp;quot;); &lt;br /&gt;
    }  &lt;br /&gt;
  }  &lt;br /&gt;
  &lt;br /&gt;
  // Return true if index is within bounds.  &lt;br /&gt;
  private bool ok(int index) {  &lt;br /&gt;
    if(index &amp;gt;= lowerBound &amp;amp; index &amp;lt;= upperBound) return true;  &lt;br /&gt;
    return false;  &lt;br /&gt;
  }  &lt;br /&gt;
}   &lt;br /&gt;
   &lt;br /&gt;
// Demonstrate the index-range array.  &lt;br /&gt;
public class RangeArrayDemo1 {   &lt;br /&gt;
  public static void Main() {   &lt;br /&gt;
    try { &lt;br /&gt;
      RangeArray ra = new RangeArray(-5, 5);  &lt;br /&gt;
      RangeArray ra2 = new RangeArray(1, 10);  &lt;br /&gt;
 &lt;br /&gt;
      // Demonstrate ra &lt;br /&gt;
      Console.WriteLine(&amp;quot;Length of ra: &amp;quot; + ra.Length); &lt;br /&gt;
 &lt;br /&gt;
      for(int i = -5; i &amp;lt;= 5; i++) &lt;br /&gt;
        ra[i] = i; &lt;br /&gt;
   &lt;br /&gt;
      Console.Write(&amp;quot;Contents of ra: &amp;quot;); &lt;br /&gt;
      for(int i = -5; i &amp;lt;= 5; i++) &lt;br /&gt;
        Console.Write(ra[i] + &amp;quot; &amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
      Console.WriteLine(&amp;quot;\n&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
      // Demonstrate ra2 &lt;br /&gt;
      Console.WriteLine(&amp;quot;Length of ra2: &amp;quot; + ra2.Length); &lt;br /&gt;
 &lt;br /&gt;
      for(int i = 1; i &amp;lt;= 10; i++) &lt;br /&gt;
        ra2[i] = i; &lt;br /&gt;
 &lt;br /&gt;
      Console.Write(&amp;quot;Contents of ra2: &amp;quot;); &lt;br /&gt;
      for(int i = 1; i &amp;lt;= 10; i++) &lt;br /&gt;
        Console.Write(ra2[i] + &amp;quot; &amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
      Console.WriteLine(&amp;quot;\n&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    } catch (RangeArrayException exc) { &lt;br /&gt;
       Console.WriteLine(exc); &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    // Now, demonstrate some errors. &lt;br /&gt;
    Console.WriteLine(&amp;quot;Now generate some range errors.&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    // Use an invalid constructor. &lt;br /&gt;
    try { &lt;br /&gt;
      RangeArray ra3 = new RangeArray(100, -10); // Error &lt;br /&gt;
   &lt;br /&gt;
    } catch (RangeArrayException exc) { &lt;br /&gt;
       Console.WriteLine(exc); &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    // Use an invalid index. &lt;br /&gt;
    try { &lt;br /&gt;
      RangeArray ra3 = new RangeArray(-2, 2);  &lt;br /&gt;
 &lt;br /&gt;
      for(int i = -2; i &amp;lt;= 2; i++) &lt;br /&gt;
        ra3[i] = i; &lt;br /&gt;
 &lt;br /&gt;
      Console.Write(&amp;quot;Contents of ra3: &amp;quot;); &lt;br /&gt;
      for(int i = -2; i &amp;lt;= 10; i++) // generate range error &lt;br /&gt;
        Console.Write(ra3[i] + &amp;quot; &amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
    } catch (RangeArrayException exc) { &lt;br /&gt;
       Console.WriteLine(exc); &lt;br /&gt;
    } &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==uses some of the properties of the Exception class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
public class Starter {&lt;br /&gt;
    public static bool bException = true;&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        try {&lt;br /&gt;
            MethodA();&lt;br /&gt;
        } catch (Exception except) {&lt;br /&gt;
            Console.WriteLine(except.Message);&lt;br /&gt;
            bException = false;&lt;br /&gt;
            except.TargetSite.Invoke(null, null);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public static void MethodA() {&lt;br /&gt;
        if (bException) {&lt;br /&gt;
            throw new ApplicationException(&amp;quot;exception message&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use the NullReferenceException==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Use the NullReferenceException. &lt;br /&gt;
 &lt;br /&gt;
using System;  &lt;br /&gt;
  &lt;br /&gt;
class X { &lt;br /&gt;
  int x; &lt;br /&gt;
  public X(int a) { &lt;br /&gt;
    x = a; &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
  public int add(X o) { &lt;br /&gt;
    return x + o.x; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
   &lt;br /&gt;
// Demonstrate NullReferenceException. &lt;br /&gt;
public class NREDemo {   &lt;br /&gt;
  public static void Main() {   &lt;br /&gt;
    X p = new X(10); &lt;br /&gt;
    X q = null; // q is explicitly assigned null &lt;br /&gt;
    int val; &lt;br /&gt;
 &lt;br /&gt;
    try { &lt;br /&gt;
      val = p.add(q); // this will lead to an exception &lt;br /&gt;
    } catch (NullReferenceException) { &lt;br /&gt;
      Console.WriteLine(&amp;quot;NullReferenceException!&amp;quot;); &lt;br /&gt;
      Console.WriteLine(&amp;quot;fixing...\n&amp;quot;); &lt;br /&gt;
 &lt;br /&gt;
      // now, fix it &lt;br /&gt;
      q = new X(9);   &lt;br /&gt;
      val = p.add(q); &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;val is {0}&amp;quot;, val); &lt;br /&gt;
  &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using checked and unchecked==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Using checked and unchecked. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
public class CheckedDemo {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    byte a, b; &lt;br /&gt;
    byte result; &lt;br /&gt;
 &lt;br /&gt;
    a = 127; &lt;br /&gt;
    b = 127; &lt;br /&gt;
  &lt;br /&gt;
    try {  &lt;br /&gt;
      result = unchecked((byte)(a * b)); &lt;br /&gt;
      Console.WriteLine(&amp;quot;Unchecked result: &amp;quot; + result); &lt;br /&gt;
 &lt;br /&gt;
      result = checked((byte)(a * b)); // this causes exception &lt;br /&gt;
      Console.WriteLine(&amp;quot;Checked result: &amp;quot; + result); // won&amp;quot;t execute &lt;br /&gt;
    }  &lt;br /&gt;
    catch (OverflowException exc) {  &lt;br /&gt;
      // catch the exception  &lt;br /&gt;
      Console.WriteLine(exc); &lt;br /&gt;
    }  &lt;br /&gt;
  }  &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using checked and unchecked with statement blocks==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Using checked and unchecked with statement blocks. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
public class CheckedBlocks {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
    byte a, b; &lt;br /&gt;
    byte result; &lt;br /&gt;
 &lt;br /&gt;
    a = 127; &lt;br /&gt;
    b = 127; &lt;br /&gt;
  &lt;br /&gt;
    try {  &lt;br /&gt;
      unchecked { &lt;br /&gt;
        a = 127; &lt;br /&gt;
        b = 127; &lt;br /&gt;
        result = unchecked((byte)(a * b)); &lt;br /&gt;
        Console.WriteLine(&amp;quot;Unchecked result: &amp;quot; + result); &lt;br /&gt;
 &lt;br /&gt;
        a = 125; &lt;br /&gt;
        b = 5; &lt;br /&gt;
        result = unchecked((byte)(a * b)); &lt;br /&gt;
        Console.WriteLine(&amp;quot;Unchecked result: &amp;quot; + result); &lt;br /&gt;
      } &lt;br /&gt;
 &lt;br /&gt;
      checked { &lt;br /&gt;
        a = 2; &lt;br /&gt;
        b = 7; &lt;br /&gt;
        result = checked((byte)(a * b)); // this is OK &lt;br /&gt;
        Console.WriteLine(&amp;quot;Checked result: &amp;quot; + result); &lt;br /&gt;
 &lt;br /&gt;
        a = 127; &lt;br /&gt;
        b = 127; &lt;br /&gt;
        result = checked((byte)(a * b)); // this causes exception &lt;br /&gt;
        Console.WriteLine(&amp;quot;Checked result: &amp;quot; + result); // won&amp;quot;t execute &lt;br /&gt;
      } &lt;br /&gt;
    }  &lt;br /&gt;
    catch (OverflowException exc) {  &lt;br /&gt;
      // catch the exception  &lt;br /&gt;
      Console.WriteLine(exc); &lt;br /&gt;
    }  &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using Exception members==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Using Exception members. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class ExcTest { &lt;br /&gt;
  public static void genException() { &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;
        Console.WriteLine(&amp;quot;nums[{0}]: {1}&amp;quot;, i, nums[i]); &lt;br /&gt;
      } &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;this won&amp;quot;t be displayed&amp;quot;);  &lt;br /&gt;
  } &lt;br /&gt;
}     &lt;br /&gt;
 &lt;br /&gt;
public class UseExcept {  &lt;br /&gt;
  public static void Main() {  &lt;br /&gt;
  &lt;br /&gt;
    try {  &lt;br /&gt;
      ExcTest.genException(); &lt;br /&gt;
    }  &lt;br /&gt;
    catch (IndexOutOfRangeException exc) {  &lt;br /&gt;
      // catch the exception  &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;
    }  &lt;br /&gt;
    Console.WriteLine(&amp;quot;After catch statement.&amp;quot;);  &lt;br /&gt;
  }  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>