The Error Shield

Medium+20 XP

Mission Briefing

The Energy Shield generator is highly unstable! You must initiate the launch sequence, but also deploy an absolute defense metric to catch any catastrophic explosions before they destroy the ship.

The Concept: Error Handling

The try...catch statement runs a block of code. If an error is thrown anywhere inside the try block, execution immediately jumps to the catch block, preventing the entire program from crashing!

The Objective

Your function receives a callback unsafeFunction.

  1. Wrap the execution of unsafeFunction() entirely within a try/catch block.
  2. If it succeeds without an error, return whatever the function evaluated to.
  3. If an error is caught, immediately return the exact string "Error Caught".

01EXAMPLE 1

InputunsafeFunction = () => { throw new Error() }
Output"Error Caught"

Constraints

  • You must use a try/catch block.
AdvancedErrors
JavaScript
Loading...
3 Hidden

Input Arguments

unsafeFunction"___FN___:return function(){return 'OK'}"

Expected Output

OK

Click RUN to test your solution