2011-12-20 12 views
1

私はC#でカスタム例外クラスを持っています。例外はなしコンストラクタを持っていないので、C#でコンストラクタのドキュメントを継承していますか?

public class InformationException : Exception {} 

今、もちろん、これは、動作しません。

i 実際にを追加する必要がありますか? :

public class InformationException : Exception 
{ 
    public InformationException() : base() {} 
    public InformationException(string message): base(message) {} 
    public InformationException(string message, Exception innerException) : base(message, innerException) {} 
} 

しかし、その後、クラスのために、実際に私はドキュメントを追加する必要が有用である:

私は今のところ繰り返す必要が
public class InformationException : Exception 
{ 
    /// <summary> 
    /// Initializes a new instance of the System.Exception class. 
    /// </summary> 
    public InformationException() : base() {} 

    /// <summary> 
    /// Initializes a new instance of the System.Exception class with a specified error message. 
    /// </summary> 
    /// <param name="message"> The message that describes the error.</param> 
    public InformationException(string message): base(message) {} 

    /// <summary> 
    /// Initializes a new instance of the System.Exception class with a specified error message and a reference to the inner exception that is the cause of this exception. 
    /// </summary> 
    /// <param name="message"> The error message that explains the reason for the exception.</param> 
    /// <param name="innerException">The exception that is the cause of the current exception, or a null reference 
    /// (Nothing in Visual Basic) if no inner exception is specified.</param> 
    public InformationException(string message, Exception innerException) : base(message, innerException) {} 
} 

public class ClientException : InformationException { } 

public class BusinessRuleException : InformationException { } 

public class InvisibleException : Exception { } 

public class ProgrammerException : InvisibleException { } 

ありhasn私が逃したC#in the last 3 yearsの変更はありませんか?これはまだですクラスを継承する方法ですか?


更新:おっと、あなたはまた、保護されたコンストラクタを提供する必要が判明:

public class InformationException : Exception 
{ 
    public InformationException() : base() {} 
    public InformationException(string message): base(message) {} 

    /// <summary> 
    /// Initializes a new instance of the System.Exception class with serialized data. 
    /// </summary> 
    /// <param name="info">The System.Runtime.Serialization.SerializationInfo that holds the serialized 
    /// object data about the exception being thrown.</param> 
    /// <param name="context">The System.Runtime.Serialization.StreamingContext that contains contextual 
    /// information about the source or destination.</param> 
    /// <exception cref="System.ArgumentNullException">The info parameter is null</exception> 
    /// <exception cref="System.Runtime.Serialization.SerializationException">The class name is null or System.Exception.HResult is zero (0).</exception> 
    protected InformationException(SerializationInfo info, StreamingContext context); 

    protected Exception(SerializationInfo info, StreamingContext context): base(info, context) {} 
    public InformationException(string message, Exception innerException) : base(message, innerException) {} 
} 
+0

もちろん、この」の意味を定義を使用することができますもちろん動作しません "。 *有用かどうかは別問題です。 –

+0

ほぼ正確に重複しています:http://stackoverflow.com/questions/426484/why-are-constructors-not-inherited – ChrisWue

+0

@ChrisWueはい、2009年以降にC#言語の開発があったのかどうか疑問に思っていました。具体的には、私の問題を解決するために、いくつかの '

'構文があります。 –

答えて

1

this answerで説明したように、あなたがGhostDoc

+0

コードをコピーすると匂いがする。 – CodesInChaos

+0

私は同意しますが、それがOPが望んでいるものなら、そこに何かがあります。 – aqwert

+0

@aqwet例外をスローしたい人は、それを作成する方法が必要です...(?) –

関連する問題