略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: THROW

2024-03-28

THROW

PHP code

<?php
/*
 * 
 * opcode number: 108
 */
try {
    
$error 'Always throw this error';
    throw new 
Exception($error);

    
// Code following an exception is not executed.
    
echo 'Never executed';

} catch (
Exception $e) {
    echo 
'Caught exception: ',  $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>

PHP opcodes

Function name: (null)

Compiled variables: !0=$error, !1=$e

line#op fetchextreturn operands
70 ASSIGN     !0,'Always+throw+this+error'
81 ZEND_FETCH_CLASS   :1 'Exception'
 2 NEW   $2 :1
 3 SEND_VAR     !0
 4 DO_FCALL_BY_NAME  1   
 5 ZEND_THROW  0  $2
116 ECHO     'Never+executed'
137 JMP     ->15
 8 ZEND_FETCH_CLASS   :4 'Exception'
 9 ZEND_CATCH  15  $4,!1
1410 ECHO     'Caught+exception%3A+'
 11 ZEND_INIT_METHOD_CALL     !1,'getMessage'
 12 DO_FCALL_BY_NAME  0   
 13 ECHO     $6
 14 ECHO     '%0A'
1815 ECHO     'Hello+World'
1916 RETURN     1
add a note add a note

User Contributed Notes 1 note

up
-17
Mokrator
1 year ago
concider use of "trigger_error()"

you can define the type of error to log an error.

trigger_error('usererror occured...', E_ERROR);

take care if you are using variables in the error-text that they could cause a security risk due to that they are not escaped or can contain html (including <script>) code if the error gets echo'ed to the browser.

官方地址:https://www.php.net/manual/en/internals2.opcodes.throw.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3