Are there any best practices for using the "finally" block in PHP when handling exceptions?

When handling exceptions in PHP, it is a best practice to use a "finally" block to ensure that certain code is executed regardless of whether an exception is thrown or not. This can be useful for cleaning up resources, closing connections, or performing any necessary actions that should always be executed.

try {
    // Code that may throw an exception
    throw new Exception("An error occurred");
} catch (Exception $e) {
    // Handle the exception
    echo "Caught exception: " . $e->getMessage();
} finally {
    // Code that should always be executed
    echo "Finally block executed";
}