Your Exceptions
class needs to define all constructors you want to provide. The constructors of System.Exception
are not virtual or abstract. The keyword base
does not call the members of all base classes, but of the one base class you provide in the class declaration. Take a look at this:
public class Exceptions : Exception
{
public Exceptions(string message)
: base(message) {}
}
public class ProccessIsNotStarted : Exceptions
{
public ProccessIsNotStarted()
: base()
{
}
public ProccessIsNotStarted(string message)
: base(message)
{
// This will work, because Exceptions defines a constructor accepting a string.
}
public ProccessIsNotStarted(string message, Exception e)
: base(message, e)
{
// This will not work, because Exceptions does not define a constructor with (string, Exception).
}
}
The parameterless constructor gets defined by default. To hide it you need to declare it private
.
Regarding to the MSDN you should keep your exception inheritance hierarchy flat:
If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value.
You might also take a look at this page.