Обработка исключений

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

throwIfTrue(true);
//printed: "catch" and "finally"
throwIfTrue(false);
//printed only "finally"