PHP錯誤: Exception thrown without a stack frame in Unknown on line 0[轉載],thrownstack_PHP教程

來源:互聯網
上載者:User

PHP錯誤: Exception thrown without a stack frame in Unknown on line 0[轉載],thrownstack


來自:網易部落格

就目前我的瞭解,在兩種情況下,PHP會報 Exception thrown without a stack frame in Unknown on line 0這種錯誤:

1)異常捕捉用了set_exception_handler導向,Exception裡面執行另一個Exception

如下面這段代碼,就會出現這種問題:

http://de.php.net/manual/de/function.set-exception-handler.php#88082

function error_handler($code, $message, $file, $line){    if (0 == error_reporting())        return;            throw new ErrorException($message, 0, $code, $file, $line);}function exception_handler($e){    // ... normal exception stuff goes here    print $undefined; // This is the underlying problem}set_error_handler("error_handler");set_exception_handler("exception_handler");throw new Exception("Just invoking the exception handler");

exception_handler函數內print $undefined;這行本身會拋出一個異常,而他又去調用set_exception_handler的exception_handler函數,死迴圈了。

解決辦法:不要在一個Exception裡面執行另一個Exception

上面的問題可以用try ... catch的方式,如exception_handler改成下面這樣:

function exception_handler($e){    try    {        // ... normal exception stuff goes here        print $undefined; // This is the underlying problem    }    catch (Exception $e)    {        print get_class($e)." thrown within the exception handler. Message: ".$e->getMessage()." on line ".$e->getLine();    }}

2) 在解構函式拋出異常

參考這個bug:http://bugs.php.net/bug.php?id=33598

下面的代碼就會報這個錯誤:

class test {    function __construct() {        echo "Construct\n";    }    function greet() {        echo "Hello World\n";    }     function __destruct() {        echo "Destruct\n";        throw new Exception( 'test' );    }}$test = new test();$test->greet();

目前的解決辦法:

1.不要在解構函式中拋出異常.

2.由於解構函式是在退出時執行的,所以要手動unset這種類,並catch該異常。

比如上面的例子,在最後加一行unset($test),這時程式就會報throw new Exception( 'test' ); 這行有錯誤,再catch這個異常就行了。

上面兩種情況在php 5.2.11版本上都會出現,至於原因我認為PHP可能就是這樣處理的,php bug 33598 2005年就報上去了,bug Status為Closed,說明官方並不認為這是一個bug,或不當一個bug處理了。


我這開啟session錯在哪兒?

如果這個檔案不是被另一個檔案包含調用的話。。你可以試試下面的做法。

檔案不要用 UTF-8 編碼。。

把你下面的代碼移到上面去。。反正你包含的 PHP 檔案裡面也沒有 HTML 碼。

檢查你的 php.ini 注意 SESSION 臨時檔案儲存的路徑,是否可以被 PHP 訪問。
 

thinkphp在讀取sqlite資料時為何會出現中文亂碼?指點

編碼不同,有的是utf-8,有的是Unicode,所以會出現為亂碼,插入資料庫的時候設定成utf-8,讀取出來也用utf-8就行了。
 

http://www.bkjia.com/PHPjc/850752.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/850752.htmlTechArticlePHP錯誤: Exception thrown without a stack frame in Unknown on line 0[轉載],thrownstack 來自:網易部落格 就目前我的瞭解,在兩種情況下,PHP會報 Exceptio...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.