Replace finally statement to make PHP 5.4 compatibility