您的位置:首页 > 编程语言 > C语言/C++

C++异常机制 实现 使用

2008-04-11 09:38 260 查看
[align=left]今天写了一些 关于 异常处理的东东,提交的时候居然网络不能用全丢了,没办法了,我就贴一点东西上来了[/align]
[align=left] [/align]
[align=left]catch( exPoint p ) [/align]
[align=left]{ [/align]
[align=left] // do something [/align]
[align=left] throw; [/align]
[align=left]} [/align]
[align=left]and an exception object of type exVertex derived from exPoint. The two types match and the catch clause block becomes active. What happens with p?[/align]

p is initialized by value with the exception object the same as if it were a formal argument of a function. This means a copy constructor and destructor, if defined or synthesized by the compiler, are applied to the local copy.
Because p is an object and not a reference, the non-exPoint portion of the exception object is sliced off when the values are copied. In addition, if virtual functions are provided for the exception hierarchy, the vptr of p is set to exPoint's virtual table; the exception object's vptr is not copied.

[align=left]What happens when the exception is rethrown? Is p now the object propagated or the exception object originally generated at the throw site? p is a local object destroyed at the close of the catch clause. Throwing p would require the generation of another temporary. It also would mean losing the exVertex portion of the original exception. The original exception object is rethrown; any modifications to p are discarded.[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: