Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Try, Catch, Finally Order

Asynchronous JavaScriptmedium

Course · Section 16: Asynchronous JavaScript: Promises, Async/Await, and AJAX · Lecture 275: Error Handling With try...catch

Implement `trace(shouldThrow)` that records which blocks run. Push `try` on success or `catch` on failure, and always push `finally`, returning the log array.

Sample tests

Input: trace(false)
Output: ["try","finally"]
Input: trace(true)
Output: ["catch","finally"]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Assuming finally is skipped on error; it always runs.

Learning resources

  • MDN: try...catch
Visualize this concept: Promises →
Approach & explanation (try first)

The log records which path ran, showing that finally executes whether or not an error was thrown.

Loading...
⌘/Ctrl + Enter

Run your code to see results.