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]
[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]
相关文章推荐
- 使用xmlhttp 实现多文件上传
- 使用 SWIG 实现 Java 调用 C++ DLL
- (作业)使用多线程实现一个大数加程序
- Android Studio使用Robolectric对android程序实现单元测试
- 【Java EE 学习 77 下】【数据采集系统第九天】【使用spring实现答案水平分库】【未解决问题:分库查询问题】
- PHP中使用虚代理实现延迟加载技术
- 11-界面控件ListView之使用SimpleAdapter实现复杂的界面显示
- 使用cookie实现购物车
- 使用FragmentTabHost+TabLayout+ViewPager实现双层嵌套Tab
- Echarts 使用asp.net +ashx+ajax 实现 饼图、柱形图后台交互
- 关于使用SSH框架分页的实现以及容易出错的地方
- 使用 Perl 脚本实现交互式命令行程序的管理与测试自动化
- 使用js实现图片轮滑效果
- 12-界面控件之listView使用java代码和xml文件不同方式实现列表显示
- 使用ActivityOptions动画共享组件的方式实现跳转Activity动画
- Python(16)python使用tkinter实现一个简单的计算器
- 使用springboot+springsession实现分布式session以及源码解析
- [转]使用事件驱动模型实现高效稳定的网络服务器程序
- 使用Eclipse RCP创建视图并实现视图间消息传递