Created
October 16, 2018 10:47
-
-
Save albertospelta/3bcf282cb5e70cec907253af29074c27 to your computer and use it in GitHub Desktop.
Template for creating custom exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.Serialization; | |
using System.Security.Permissions; | |
namespace App.Infrastructure.Exceptions | |
{ | |
[Serializable] | |
public class SampleException: Exception, ISerializable | |
{ | |
public string CustomErrorProperty { get; set; } | |
public SampleException() | |
{ | |
} | |
public SampleException(string message) | |
: base(message) | |
{ | |
} | |
public SampleException(string message, Exception innerException) | |
: base(message, innerException) | |
{ | |
} | |
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] | |
protected SampleException(SerializationInfo info, StreamingContext context) | |
: base(info, context) | |
{ | |
CustomErrorProperty = info.GetString(nameof(CustomErrorProperty)); | |
} | |
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] | |
public override void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue(nameof(CustomErrorProperty), CustomErrorProperty); | |
base.GetObjectData(info, context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment