抛出一个std :: exception(或派生类型)的其他东西有什么好处吗? [英] Is there any advantages to throw other thing that a std::exception( or derivatives types)
问题描述
例如
有没有什么优势或用例来抛出一个std :: exception(或派生类型) throw 1; 或 throwerror;
For example throw 1;
or throw "error";
标准允许它。
推荐答案
根据§15.1[except]:
Per §15.1 [except]:
异常处理提供了一种从执行线程到异常的一个点传递控件和
信息的方式
与点相关联的处理程序以前通过执行。
Exception handling provides a way of transferring control and information from a point in the execution of a thread to an exception handler associated with a point previously passed by the execution.
单词信息说明了一切,它可以是一切,如对象,数字,...。
The word information illustrates everything, it can be everything such as objects, numbers, ... .
标准中没有什么说你必须抛出 std :: exception
。换句话说,也许有人想要抛出自己的异常对象。
There is nothing in standard that says you must just throw std::exception
. In the other words, maybe someone wants to throw his own exception objects.
也许有人想使用异常处理来处理远离正常异常的一些事情。
Maybe someone wants to use exception-handling to handle something far from normal exceptions.
这篇关于抛出一个std :: exception(或派生类型)的其他东西有什么好处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!