我一直在试着编写自己的自定义构造函数,但是出现了关于 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()
构造函数有一些奇怪的重载,或者我调用的方式不正确?