How do you handle different exceptions in PHP?
When handling different exceptions in PHP, you can use try-catch blocks to catch specific exceptions and handle them accordingly. By using multiple catch blocks, you can handle different types of exceptions separately, allowing you to provide specific error messages or take different actions based on the type of exception thrown.
try {
// Code that may throw exceptions
throw new Exception("An error occurred");
} catch (InvalidArgumentException $e) {
echo "Invalid argument exception: " . $e->getMessage();
} catch (Exception $e) {
echo "General exception: " . $e->getMessage();
}