Skip to content

Instantly share code, notes, and snippets.

@davidarobinson
Created May 26, 2019 22:30
Show Gist options
  • Save davidarobinson/51839104de39de96ce3bad6d5974a4a5 to your computer and use it in GitHub Desktop.
Save davidarobinson/51839104de39de96ce3bad6d5974a4a5 to your computer and use it in GitHub Desktop.
An example of using user defined exceptions
void Main()
{
Console.WriteLine("Do you want to continue? Enter Y for Yes or N for No");
var answer = Console.ReadLine();
if (answer.ToUpper() != "Y" && answer.ToUpper() != "N")
{
throw new InvalidAnswerException();
}
}
public class InvalidAnswerException:Exception
{
public InvalidAnswerException(){}
public InvalidAnswerException(string message):base(message){}
public InvalidAnswerException(string message, Exception inner):base(message, inner){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment