What are some common pitfalls or errors to watch out for when working with exceptions and error messages in PHP scripts?

One common pitfall when working with exceptions and error messages in PHP scripts is not properly handling exceptions, which can lead to uncaught exceptions and potentially expose sensitive information. To avoid this, always use try-catch blocks to catch and handle exceptions appropriately.

try {
    // code that may throw an exception
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}