How can the error handling in the PHP script be improved to provide more detailed information?

The error handling in the PHP script can be improved by using the try-catch block to catch specific exceptions and provide more detailed information about the error. By catching different types of exceptions, we can handle them accordingly and display specific error messages to help identify the issue.

try {
    // Code that may throw an exception
    $result = 1 / 0;
} catch (DivisionByZeroError $e) {
    echo "Division by zero error: " . $e->getMessage();
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}