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

// Employee\'s salary should not be negative // Include stack trace when excepti

ID: 3675321 • Letter: #

Question

// Employee's salary should not be negative
// Include stack trace when exception occurs
using System;
using static System.Console;
class FDebugEleven03
{
static void Main()
{
Employee emp = new Employee();
try
{
emp.IdNum = 234;
emp.Salary = -12;
}
catch (NegativeSalaryException e)
{
WriteLine(e.Message);
WriteLine(e.StackTrace);
}
}
}
public class NegativeSalaryException :
{
private static string msg =
"Employee salary is negative.";
public NegativeSalaryException() : base(msg)
{
}
}

public class Employee
{
private int idNum;
private double salary;
public int IdNum
{
get
return idNum;
set
idNum = value;
}
public double Salary
{
get
{
return salary;
}
set
{
if(value < 0)
{
NegativeSalaryException salExcep =
new NegativeSalaryException();
throw(sal);
}
salary = value;
}
}

}

Explanation / Answer

using System;
using static System.Console;
public class FDebugEleven03

{

public static void Main()
{
Employee emp = new Employee();
try
{
emp.IdNum = 234;
emp.Salary = -12;
}

catch (NegativeSalaryException e)
{

Console.WriteLine("An exception occurred!");

Console.WriteLine(e.Message);

   Console.WriteLine(e.StackTrace);

}

} //end of main method

} //end of the class

public class NegativeSalaryException : Exception
{
private static string message = "Employee salary is negative.";
public NegativeSalaryException(String message) : base(message)
{


}
} //end of the class

public class Employee
{
private int idNum;
private double salary;
public int IdNum
{
get
return idNum;
set
idNum = value;
}
public double Salary
{
get
{
return salary;
}
set
{

if(value < 0)
{
NegativeSalaryException salExcep =
new NegativeSalaryException();
throw(salExcep);
}

salary = value;
}
}

}

Now this code will run..