Created
May 26, 2019 22:30
-
-
Save davidarobinson/51839104de39de96ce3bad6d5974a4a5 to your computer and use it in GitHub Desktop.
An example of using user defined exceptions
This file contains 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
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