function doSomething() {
$resource = createResource();
try {
$result = useResource($resource);
} catch (Exception $e) {
releaseResource($resource);
log($e->getMessage());
exit();
}
releaseResource($resource);
return $result;
}
//使用finally后
function doSomething2() {
$resource = createResource();
try {
$result = useResource($resource);
return $result;
} catch (Exception $e) {
log($e->getMessage());
exit();
} finally {
releaseResource($resource);
}
}
您可能感兴趣的文章: