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.
- Wrap the execution of
unsafeFunction()entirely within a try/catch block. - If it succeeds without an error, return whatever the function evaluated to.
- If an error is caught, immediately return the exact string "Error Caught".
01EXAMPLE 1
Input
unsafeFunction = () => { throw new Error() }Output
"Error Caught"Constraints
- You must use a try/catch block.
AdvancedErrors
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
unsafeFunction"___FN___:return function(){return 'OK'}"
Expected Output
OK
Click RUN to test your solution