How can PHP handle unexpected errors like parse errors?

PHP can handle unexpected errors like parse errors by using try-catch blocks to catch exceptions. This allows the code to gracefully handle errors and prevent them from crashing the application. By wrapping potentially error-prone code in a try block and catching any exceptions in a catch block, developers can ensure that the application continues to run smoothly even in the face of unexpected errors.

try {
    // Code that may throw a parse error
} catch (ParseError $e) {
    echo "Parse error: " . $e->getMessage();
}