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語句外用,由於沒有捕獲到異常,也就沒有東西可以再拋出,這樣會導致程序以不定的方式終止(這依賴具體的編譯器)。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章