Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created January 29, 2018 23:40
Show Gist options
  • Save luisdeol/ecef3bb57b7d2975abb0eaaeca9eb6ac to your computer and use it in GitHub Desktop.
Save luisdeol/ecef3bb57b7d2975abb0eaaeca9eb6ac to your computer and use it in GitHub Desktop.
Creating a Custom Exception
using System;
using System.Runtime.Serialization;
namespace implement_exception_handling
{
class Program
{
static void Main(string[] args)
{
Console.ReadKey();
}
}
[Serializable]
public class NotSoGreatException : Exception
{
public string NotSoGreatName { get; set; }
public NotSoGreatException(string boringName)
{
NotSoGreatName = boringName;
HelpLink = "https://medium.com/@luisdeolme/";
}
public NotSoGreatException(string boringName, string message)
: base(message)
{
NotSoGreatName = boringName;
HelpLink = "https://medium.com/@luisdeolme/";
}
public NotSoGreatException(string boringName, string message, Exception innerException)
: base(message, innerException)
{
NotSoGreatName = boringName;
HelpLink = "https://medium.com/@luisdeolme/";
}
public NotSoGreatException(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
NotSoGreatName = (string) serializationInfo.GetValue("NotSoGreatName", typeof(string));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment