throw null 的问题

On the Solaris build of the product it would core dump (crash) whenever there was an syntax error in the XML input files(It crashes on Solaris but not on Windows or Linux).
 #include <iostream>
 int main(int argc, char** argv)
 {
         try
         {
                 std::cout << "About to throw exception." << std::endl;
                 throw;
         }
         catch(...)
         {
                 std::cerr << "Exception caught." << std::endl;
         }
         return 0;
 }
 output:
       About to throw exception.
       Abort (core dumped)
 Why it core dumps when throwing the exception?

这个用法本身是有问题的。throw;是重抛出,应该在catch块中被使用。

我找到的链接
http://developers.sun.com.cn/blog/wenlong/entry/200703099

我想solaris的行为是对的,转而应该研究为啥在windows和linux下不coredump

---

这个地址http://www.21ic.com/app/computer/200912/52021.htm

规则15-1-3(强制):空的 throw 语句只能出现在catch语句块中。
    空的 throw 用来将捕获的异常再抛出,可以实现多个处理程序问异常的传递。然而,如果在catch语句外用,由于没有捕获到异常,也就没有东西可以再抛出,这样会导致程序以不定的方式终止(这依赖具体的编译器)。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值