Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Taking exceptions into account

Let's enhance our logging function a bit, by considering a needed adjustment. What happens to your log if the function throws an error? Fortunately, that's easy to solve. We just have to add some code:

const addLogging2 = fn => (...args) => {    console.log(`entering ${fn.name}: ${args}`);    try {        const valueToReturn = fn(...args);        console.log(`exiting ${fn.name}: ${valueToReturn}`);        return valueToReturn;    } catch (thrownError) {        console.log(`exiting ${fn.name}: threw ${thrownError}`);        throw thrownError;    }};

Other changes would be up to you -- adding date and time data, enhancing the way parameters are listed, and so on. However, our implementation still has an important defect; let's make it better.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content