Custom exception with properties

前端 未结 1 1566
無奈伤痛
無奈伤痛 2021-01-11 21:20

After some research I found that a custom exception should look like this:

using System;
using System.Runtime.Serialization;

namespace YourNamespaceHere
{
          


        
相关标签:
1条回答
  • 2021-01-11 22:20

    It will look something like this. You look for more details here What is the correct way to make a custom .NET Exception serializable?

     [Serializable()]
            public class YourCustomException : Exception, ISerializable
            {
                public Int Id { get; set; }
                public Int ErrorCode { get; set; }
                public YourCustomException() : base() { }
                public YourCustomException(string message) : base(message) { }
                public YourCustomException(string message, System.Exception inner) : base(message, inner) { }
                public YourCustomException(SerializationInfo info, StreamingContext context) : base(info, context) { }
                public YourCustomException(string message, int Id, int ErrorCode)
                    : base(message)
                {
                    this.Id = Id;
                    this.ErrorCode = ErrorCode;
                }
            }
    
    0 讨论(0)
提交回复
热议问题