Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在a中显示异常(<;部门>;块_Php - Fatal编程技术网

Php 在a中显示异常(<;部门>;块

Php 在a中显示异常(<;部门>;块,php,Php,是否可以在特定的HTML块中显示异常消息 catch(异常$e){ //在此块中显示消息 echo$e->getMessage(); 出口 } EDIT:假设我有一个index.php文件和一个名为error的元素。我想在…中显示所有异常?对不起,你的问题不是100%清楚 <?php echo '<div>'.$e->getMessage().'</div>'; ?> 嗯?对不起,你的问题不是100%清楚 <?php echo '<div

是否可以在特定的HTML
块中显示异常消息

catch(异常$e){
//在此块中显示消息
echo$e->getMessage();
出口
}

EDIT:假设我有一个
index.php
文件和一个名为
error
元素。我想在
中显示所有异常?对不起,你的问题不是100%清楚

<?php echo '<div>'.$e->getMessage().'</div>'; ?>

嗯?对不起,你的问题不是100%清楚

<?php echo '<div>'.$e->getMessage().'</div>'; ?>

捕获(例外$e){
//要在html div块上显示消息。
echo sprintf(“%s”,$e->getMessage());
出口
}
捕获(例外$e){
//要在html div块上显示消息。
echo sprintf(“%s”,$e->getMessage());
出口
}

您可以将
$e->getMessage()存储在变量中,并在以后回显它

try {
    /* do something */
}
catch ( Exception $e ) {
    $error = $e->getMessage();
}

/* do something else */

if ( isset($error) ) {
    echo "<div>{$error}</div>";
}
试试看{
/*做点什么*/
}
捕获(例外$e){
$error=$e->getMessage();
}
/*做点别的*/
如果(isset($error)){
回显“{$error}”;
}

您可以将
$e->getMessage()存储在变量中,并在以后回显它

try {
    /* do something */
}
catch ( Exception $e ) {
    $error = $e->getMessage();
}

/* do something else */

if ( isset($error) ) {
    echo "<div>{$error}</div>";
}
试试看{
/*做点什么*/
}
捕获(例外$e){
$error=$e->getMessage();
}
/*做点别的*/
如果(isset($error)){
回显“{$error}”;
}

假设我有index.php文件。还有一个div块叫做error。假设我有index.php文件,我想显示
上的所有异常。还有一个div块叫做error。我想显示