What are the best practices for handling exceptions in PHP database access with ORM?

When handling exceptions in PHP database access with ORM, it is important to catch and handle exceptions gracefully to prevent your application from crashing. One common practice is to use try-catch blocks to catch exceptions thrown by the ORM and handle them appropriately, such as logging the error or displaying a user-friendly message.

try {
    // ORM database access code here
} catch (\Exception $e) {
    // Handle the exception
    echo "An error occurred: " . $e->getMessage();
    // Log the error
    error_log("Database error: " . $e->getMessage());
}