Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having problems with errors on this Exception handling, my codes is below:

ID: 3847169 • Letter: I

Question

I am having problems with errors on this Exception handling, my codes is below:

/***********************Program to handle multiple exceptions using catch*********************/
//Michael Cole 6/7/2017

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

namespace Except1
{
    //define class Exception1 which inherits from Exception
    public class Exception1 : Exception
    {
        /*Define constructor that would call the default base class constructor*/
        public Exception1()
            : base()
    }

    }
     /*define constructor that would call the parameterized base class constructor*/
     public Exception1(string message)
    :base(message)
    {

    }
    /*Define the constructor that will be used to invoke the base constructor two arguments @param message is the message to be printed and @param inner is the object of Exception class*/
    public Exception1(string message, Exception inner)
    :base(message, inner)
    {

    }
  
    }
    //Class Exception Test to test the application
    public class ExceptionTest
    {
     //main method
     public static void Main(string[]args)
    }
    //throw exception of type Exception1
    try
    {
    throw new Exception1("Exception thrown");
    }
    //catch exception of type Exception1
    catch (Exception e)
    {
    Console.WriteLine("Exception caught:{0}", e.StackTrace);
    }
    //throw exception of type FormatException
    try
    {
    throw new FormatException();
    }
    //catch exception of type FormatException
    catch (Exception e)
    {
    Console.WriteLine(e.StackTrace);
    }
    //throw exception of type arithmeticException
    try
    {
    throw new ArithmeticException();
    }
    //catch the exception
    catch (Exception e)
    {
    Console.WriteLine(e.StackTrace);
    }
    Console.ReadLine();
    }
    //end of main method
    }
    //end of class ExceptionTest

Explanation / Answer

braces not properly closed

Here is code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Except1
{
//define class Exception1 which inherits from Exception
public class Exception1 : Exception
{
/*Define constructor that would call the default base class constructor*/
public Exception1()
: base()
{
}
/*define constructor that would call the parameterized base class constructor*/
public Exception1(string message)
: base(message)
{
}
/*Define the constructor that will be used to invoke the base constructor two arguments @param message is the message to be printed and @param inner is the object of Exception class*/
public Exception1(string message, Exception inner)
: base(message, inner)
{
}

}
//Class Exception Test to test the application
public class ExceptionTest
{
//main method
public static void Main(string[] args)
{
//throw exception of type Exception1
try
{
throw new Exception1("Exception thrown");
}
//catch exception of type Exception1
catch (Exception e)
{
Console.WriteLine("Exception caught:{0}", e.StackTrace);
}
//throw exception of type FormatException
try
{
throw new FormatException();
}
//catch exception of type FormatException
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
//throw exception of type arithmeticException
try
{
throw new ArithmeticException();
}
//catch the exception
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
//end of main method
}
//end of class ExceptionTest
}