PHP异常处理浅析(2)


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);
    }
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4075706aaf40f254f72472adc6b0eae8.html