A Nathik

A Nathik

  • NA
  • 1
  • 1.8k

inner exception query

Nov 29 2014 8:44 PM
Hi,


I'm a newbie to C#. Trying to work on Inner exception but however the following code doesn't seem to work. Can you please help me out?
Thanks in advance!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


namespace ExceptionHandling
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                try
                {
                    Console.WriteLine("Enter your first number");
                    int FN = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Enter your Second number");
                    int SN = Convert.ToInt32(Console.ReadLine());
                    int Result = FN / SN;
                    Console.WriteLine("Result is {0}", FN/SN);
                    Console.ReadLine();
                }
                catch (Exception E)
                {
                    string path = @"C:\Users\abdulhanannajjara\Desktop\Test.txt";
                   
                    if(File.Exists(path))
                    {
                        StreamWriter SW = new StreamWriter(path);
                        SW.Write(E.Message);
                        //SW.Write();
                        SW.WriteLine(E.Message, E.Source);
                        SW.Close();
                        Console.WriteLine("There is a problem");
                    }
                    else
                    {
                        throw new FileNotFoundException("File not found" + path, E);
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("Current Exception {0}", ex.GetType().Name);
                Console.WriteLine("Inner Exception {1}", ex.InnerException.GetType().Name);
            }
        }
    }
}



Answers (2)