TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326.3k
Exception Handling (8e5)
Feb 8 2012 5:06 PM
class EmployeeException : Exception
{
public EmployeeException(string idAndPayRate) : base(idAndPayRate + "is invalid")
{
}
}
Can you please explain how did you decide argument is the base ((idAndPayRate + "is invalid")).
using System;
namespace _8e5
{
class EmployeeExceptionDemo
{
static void Main(string[] args)
{
Employee emp1 = CreateEmployee("12", 4);
Employee emp2 = CreateEmployee("34", 20);
Employee emp3 = CreateEmployee("56", 60);
Console.ReadKey();
}
static Employee CreateEmployee(string IDNum, double hourlyWage)
{
Employee emp = null;
try
{
emp = new Employee(IDNum, hourlyWage);
}
catch (EmployeeException ee)
{
Console.WriteLine(ee.Message);
}
return emp;
}
}
class EmployeeException : Exception
{
public EmployeeException(string idAndPayRate) : base(
idAndPayRate + " is invalid"
)
//????????????????
{
}
}
class Employee
{
public readonly string IDNum;
public readonly double hourlyWage;
public Employee(string IDNum, double hourlyWage)
{
if (hourlyWage < 6.0 || hourlyWage > 50.0)
throw new EmployeeException(String.Format("ID Number {0}, Pay Rate {1}", IDNum, hourlyWage));
this.IDNum = IDNum;
this.hourlyWage = hourlyWage;
}
}
}
/*
ID Number 12, Pay Rate 4 is invalid
ID Number 56, Pay Rate 60 is invalid
*/
Attachment:
chapter8-exercises.zip
Reply
Answers (
4
)
Collection in C#
How play sound on telephone line