您的当前位置:首页>全部文章>文章详情

PHP错误处理代码

发表于:2024-03-02 20:28:30浏览:95次TAG: #PHP

PHP错误处理:

<?php  
try {  
    $file = fopen('non_existent_file.txt', 'r');  
    if ($file) {  
        echo "File opened successfully.";  
    } else {  
        throw new Exception("Failed to open file.");  
    }  
} catch (Exception $e) {  
    echo "Error: " . $e->getMessage();  
}  
?>