异常处理中的 throw 语句用于抛出异常,rethrow 语句用于在捕获的异常中再次抛出相同的异常。throw 语句的语法为:throw exception_object; rethrow 语句的语法为:rethrow; throw 和 rethrow 语句仅在需要向调用者报告错误时使用,且异常信息需清晰有用。
C++ 函数异常处理中的 throw 和 rethrow 语句
异常是运行时发生的错误或异常情况,可以使用 throw 语句抛出。rethrow 语句用于在捕获的异常中再次抛出相同的异常。
throw 语句
throw 语句用于抛出一个异常对象。其语法如下:
throw exception_object;