【发布时间】:2013-01-26 07:51:37
【问题描述】:
我一直在尝试编写自己的自定义构造函数,但收到关于 base() 构造函数的错误。我也一直在寻找如何解决这个错误,但一无所获,互联网上的所有示例都显示与我几乎相同的代码。
整个 Exception.cs 内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace RegisService
{
public class Exceptions : Exception
{
}
public class ProccessIsNotStarted : Exceptions
{
ProccessIsNotStarted()
: base()
{
//var message = "Formavimo procesas nestartuotas";
//base(message);
}
ProccessIsNotStarted(string message)
: base(message) {}
ProccessIsNotStarted(string message, Exception e)
: base(message, e) {}
}
}
base() 的第一个重载正在工作,没有引发错误。第二个和第三个
重载告诉我:
"RegisService.Exceptions 不包含一个构造函数 1(2)个论点”
我一直在尝试解决错误的另一种方法:
ProccessIsNotStarted(string message)
{
base(message);
}
ProccessIsNotStarted(string message, Exception e)
{
base(message, e);
}
这一次,VS 告诉我:
“在此上下文中使用关键字'base'无效”
那么,问题出在哪里?看起来base() 构造函数有一些奇怪的重载,或者我以不恰当的方式调用它?
【问题讨论】:
标签: c# exception base custom-exceptions