确保执行(finally)

异常处理

function throwIfTrue(param) {
    try {
        if (param)
            throw new Error("test exception");
    }
    catch (e) {
        console.log("catch");
    }
    finally {
        console.log("finally");
    }
}

throwIfTrue(true);
//输出 "catch" 和 "finally"
throwIfTrue(false);
//只输出 "finally"