From de074cc615489e5a59e3525e11f423468c89f2ec Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Thu, 5 Sep 2024 11:28:39 -0400 Subject: [PATCH 1/3] Improve lab handling-errors.html Improve lab handling-errors.html. In particular, add some hints for the last section. Signed-off-by: David A. Wheeler --- docs/labs/handling-errors.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/labs/handling-errors.html b/docs/labs/handling-errors.html index f4e276d6..4e372dfa 100644 --- a/docs/labs/handling-errors.html +++ b/docs/labs/handling-errors.html @@ -111,6 +111,23 @@ text: Catch an object named err within the catch block. examples: - - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (foo) {" +- index: 2 + absent: |- + catch \( err \) + text: >- + Please use `catch(err) {...}` for purposes of this lab. +- index: 2 + present: |- + console \. error \( ["'][^"']*["'] , result \. message + 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.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);" # debug: true From 28fec2e951e86b679fc61fb98534dd472e8b8891 Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Thu, 5 Sep 2024 12:03:36 -0400 Subject: [PATCH 2/3] handling-errors.html: Tweak hints Signed-off-by: David A. Wheeler --- docs/labs/handling-errors.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/labs/handling-errors.html b/docs/labs/handling-errors.html index 4e372dfa..d85be4c2 100644 --- a/docs/labs/handling-errors.html +++ b/docs/labs/handling-errors.html @@ -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 @@ -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 @@ -106,16 +111,13 @@ text: Use 'catch (...) {...}' to catch an error object within the catch block. 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. - examples: - - - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (foo) {" - index: 2 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: |- console \. error \( ["'][^"']*["'] , result \. message From 0b164e00b372df21b42697e2b4f8075d88630690 Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Thu, 5 Sep 2024 12:50:36 -0400 Subject: [PATCH 3/3] handling-errors.html: Improve lab Signed-off-by: David A. Wheeler --- docs/labs/handling-errors.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/labs/handling-errors.html b/docs/labs/handling-errors.html index d85be4c2..6a628d83 100644 --- a/docs/labs/handling-errors.html +++ b/docs/labs/handling-errors.html @@ -120,16 +120,17 @@ - - " try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (foo) {" - index: 2 present: |- - console \. error \( ["'][^"']*["'] , result \. message + 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.message, since - the error is in `err.message`. Note that + 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