Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions docs/labs/handling-errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
- - " return { result: a / b };"
- index: 2
absent: '\s*try\s*{\s* '
text: Use a try block to catch any exceptions that might be thrown.
text: >-
Use a try block to catch any exceptions that might be thrown.
It should look something like `try { ... } catch(err) {...}`
(fill in the `...` sections).
examples:
- - " const result = divide(10, 2);"
- index: 2
Expand All @@ -98,7 +101,9 @@
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result.result ); "
- index: 2
absent: '.*? catch .*? '
text: Handle the error within the catch block.
text: >-
Handle the error within the catch block. You need `catch(err) {...}`
after `try {...}` to catch an error in the try block.
examples:
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); }"
- index: 2
Expand All @@ -107,10 +112,25 @@
examples:
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch {}"
- index: 2
absent: '\s* catch \s* \( err \) { \s* '
text: Catch an object named err within the catch block.
absent: |-
catch \( err \)
text: >-
Please use `catch(err) {...}` for purposes of this lab.
examples:
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (foo) {"
- index: 2
present: |-
catch .* console \. error \( ["'][^"']*["'] , result
text: >-
When reporting the error, you need to report it in the catch block,
which catches it as the variable `err`.
Thus, you need to use `err.message` not `result` or `result.message`,
since the error is in `err.message`. Note that
the variable `result` is out of scope in the catch block anyway;
it was declared in the try block.
examples:
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (err) { console.error('Error', result.message);"
- - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (err) { console.error('Error', result );"
# debug: true
</script>
</head>
Expand Down
Loading