Now that we've thrown an error, it's our job to safely handle the possible outcomes that calling RestartLevel() might have because at this point, this is not addressed properly. The way to do this is with a new kind of statement, called try-catch:
try
{
// Call a method that might throw an exception
}
catch (ExceptionType localVariable)
{
// Catch all exception cases individually
}
The try-catch statement is made up of consecutive code blocks that are executed on different conditions; it's like a specialized if/else statement. We call any methods that potentially throw exceptions in the try block—if no exceptions are thrown, the code keeps executing without interruption. If an exception is thrown, the code jumps to the catch statement that matches the thrown exception, just like switch statements do with their cases. catch statements need to define what exception they are accounting for and specify a local variable name that will represent it...