开发者

Strange, one expression generates exception but another one not [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I've faced some difficulty...

function generateExceptionOrError() {
    throw new Exception();
}

Code below will display Fatal error: Uncaught exception 'E开发者_C百科xception':

<? generateExceptionOrError();?>

Code below will also display Fatal error: Uncaught exception 'Exception':

<?=generateExceptionOrError();?>

But another code below will be silent and wouldn't output any information about unhandled Excetions. It would display absolute nothing, blank page... Of course, I suppose that Exception is generated, but why it is not displayed!?

<link rel="stylesheet" href="<?=generateExceptionOrError();?>" type="text/css">

Why? What am I missing?

Thank you

UPDATED: There is not difference exception is generated in method or another kind of errors. The same situation.


One thing I've notice in testing is that if an exception occurs inside the "'s of an elements attribute, the entire element is not displayed as well as any output afterwards. It seems it might be a browsers/html quirk. Try running your script on the command line and see what output you get.

Example:

<html>
<head>
<link rel="stylesheet" href="<?php generateExceptionOrError() ?>" type="text/css">
</head>
<body>
</body>
</html>

Outputs:

<html>
<head>

Running this on the command line outputs:

<html>
<head>
<link rel="stylesheet" href="PHP Fatal error:  Uncaught exception 'Exception' with message 'aaa' in /var/www/projects/test.php:4
Stack trace:
#0 /var/www/projects/test.php(11): generateExceptionOrError()
#1 {main}
  thrown in /var/www/projects/test.php on line 4

Notice the <link rel="stylesheet" href=" which is what you would have expected.

This could be at the root of your issue.


the error is there you just cant see it. use firebug or view the source and you will see something like this in your header

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜