Your code can throw an exception to indicate that some sort of error occurred. You’ll typically do this to indicate that something has gone wrong and the execution of the method cannot continue.

To throw an exception, you create an instance of the System.Exception class, or one of its derived classes, to contain information about what went wrong. You use the throw statement to throw the exception. Control returns immediately to the calling function and the exception “bubbles up” the call stack, looking for a calling method that can handle the exception.