DEV Community

Danphe
Danphe

Posted on

Guess the error message

Can you guess the correct error message this program will throw when executed, also do mention why?

class HookExecutor { constructor() { this.hooks = []; } async exec() { try { this.hooks.forEach((fn) => fn()); } catch (Err) { console.log( "Error 3: caught inside exec function where all hooks are executed." ); } } process() { this.exec().catch((error) => { console.log("Error 2: caught inside new HooksExecutor.process", error); }); } } const hookExecutor = new HookExecutor(); try { hookExecutor.hooks.push(async () => { console.log("I am a hooks"); throw new Error("Serious Error!"); }); } catch (err) { console.log("Error 1: Caught in global space", err); } hookExecutor.process(); 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)