Catches an exception that was thrown in a component : Exception Try Catch : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Try Catch »

 

Catches an exception that was thrown in a component








    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// FileOpen.cs -- Catches an exception that was thrown in a component
//
//                Compile this program with the following command line:
//                    C:>csc /r:fopen.dll FileOpen.cs
//
namespace nsFileOpen
{
    using System;
    using System.IO;
    class clsMain
    {
        static public void Main ()
        {
            clsFile file;
            try
            {
                file = new clsFile ("");
            }
            catch (Exception e)
            {
                Console.WriteLine (e.Message);
                Console.WriteLine ("Exception handled in client");
            }
        }
    }
}


// Fopen.cs -- program to show exception handling in a component
//
//             Compile this program with the following command line:
//                 C:>csc /t:library Fopen.cs
//
namespace nsFileOpen
{
    using System;
    using System.IO;
    public class clsFile
    {
        FileStream strm;
        public clsFile (string FileName)
        {
            strm = new FileStream (FileName, FileMode.Open,
                                             FileAccess.Read);
        }
    }
}



           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Try Catch