Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MultiplicatorUnitFailure extends Error {}
- function primitiveMultiply(a, b) {
- if (Math.random() < 0.2) {
- return a * b;
- } else {
- throw new MultiplicatorUnitFailure("Klunk");
- }
- }
- function reliableMultiply(a, b) {
- try {
- return primitiveMultiply(a, b);
- } catch (e) {
- if (e instanceof MultiplicatorUnitFailure) {
- return reliableMultiply(a, b);
- } else {
- throw e;
- }
- }
- }
- console.log(reliableMultiply(8, 8));
- // → 64
Add Comment
Please, Sign In to add comment