【问题标题】:How can I get the text of an error code?如何获取错误代码的文本?
【发布时间】:2016-12-12 06:55:54
【问题描述】:

我想打印“解析错误”、“致命错误”、“警告”而不是$exception->getCode(),我该怎么做?

function exception_handler( $exception ) 
{

    /*
     * Parse error: syntax error, unexpected 'w' (T_STRING), expecting ';' or '{' in C:\xampp\htdocs\dermaquality\aplicacion\vista\paginas\Dermaquality\proceso\indicadores.php on line 25
     */


    //echo $exception->__toString();
    echo "<strong>" . $exception->getCode() . ": " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine() . "</strong><br/>\n";
    echo str_replace( '#', '<br/>#', $exception->getTraceAsString() );
}

set_exception_handler('exception_handler');

【问题讨论】:

    标签: php exception error-handling exception-handling


    【解决方案1】:

    您可以尝试返回最后一个错误的函数error_get_last

    <?php
    echo $a;
    print_r(error_get_last());
    ?>
    

    那会打印出来

    Array
    (
    [type] => 8
    [message] => Undefined variable: a
    [file] => C:\WWW\index.php
    [line] => 2
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2013-01-30
      • 2013-10-17
      • 2018-07-28
      • 2018-11-16
      • 2012-11-07
      相关资源
      最近更新 更多