}
/// <summary>
/// 计算类
/// </summary>
public static class Calculation
{
/// <summary>
/// 除法
/// </summary>
public static double DividedBy(int a, int b)
{
double result = 0.0;
if (b == 0)
{
MyException ex = new MyException("除数不能为零",true);
throw ex;
}
result = a / b;
return result;
}
}
[Serializable]
public class MyException : Exception,ISerializable
{
/// <summary>
/// 新增字段,用以判断是否将异常写入日志文件
/// </summary>
private bool _isLog=false ;
public bool IsLog
{
get { return _isLog; }
}
public MyException():base() { }
//为新增字段实现构造函数
public MyException(string message, bool isLog)
: base(message)
{
_isLog = isLog;