19c02-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 27 行

PHP
27
字号
<?php// Begin a try block so that we can catch any exceptions that happen:try {    // Let's generate a random number from 1 to 10    $num = rand(1,10);        // Ensure that the number is less than 3    if ($num < 3) {        // It's not, throw an appropriate exception        throw new Exception('Number is too small');    }        // Now also don't allow the number to be greater than 7    if ($num > 7) {        // Another exception        throw new Exception('Number is too big');    }        // Otherwise, we are happy with the number...    echo "<p>Our new number is: {$num}</p>\n";} catch (Exception $e) {    // We caught the exception, so let's give the error to the user    echo '<p>Exception: ', $e->getMessage(), "</p>\n";}echo "<p>Done!</p>";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?