如果需要在程序中自行抛出异常,则应使用 throw 语句,throw 语句可以单独使用,throw 语句抛出的不是异常类,而是一个异常实例,而且每次只能抛出一个异常实例。
    throw 语法的语法格式如下:
    throw ExceptionInstance;

    throw 抛出异常 - 图1