Skip to content

Commit 1c87531

Browse files
committed
edit introduction.md proof.ci.js and error-handling.js
1 parent 272f673 commit 1c87531

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

exercises/practice/error-handling/.docs/introduction.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ You will learn how to:
77
- Check input types and throw errors for invalid inputs.
88
- Throw errors for specific cases (e.g., empty strings).
99
- Return the uppercase version of the string if it is valid.
10+
- Handle and catch errors using a try..catch block
1011

11-
Your function should:
1212

13-
- Throw a `TypeError` if input is not a string.
14-
- Throw a general `Error` if input is an empty string.
15-
- Return the uppercase form of the string 'hello'.
13+
Implement the processString function using a `try…catch` block.
14+
15+
Inside the `try` block:
16+
17+
- If the input is not a string, throw a `TypeError`.
18+
19+
- If the input is an empty string, throw a generic `Error`.
20+
21+
- Otherwise, return the input in `uppercase`.
22+
23+
Inside the `catch` block:
24+
- console log the `error` message
25+
- `throw` the `error` so it can be tested for its type.
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
export const processString = (input) => {
2-
if (typeof input !== 'string') {
3-
throw new TypeError();
2+
try {
3+
if (typeof input !== 'string') {
4+
throw new TypeError('Input must be a string');
5+
}
6+
if (input === '') {
7+
throw new Error('Input cannot be empty');
8+
}
9+
return input.toUpperCase();
10+
} catch (error) {
11+
console.log(error.message);
12+
throw error;
413
}
5-
if (input === '') {
6-
throw new Error();
7-
}
8-
return input.toUpperCase();
914
};
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
//
2+
// This is only a SKELETON file for the 'Error handling' exercise. It's been provided as a
3+
// convenience to get you started writing code faster.
4+
//
5+
16
export const processString = (input) => {
2-
//TODO: implement this
3-
//should throw TypeError if input is not a string
4-
//should throw a general Error if input is an empty string
5-
//should return the uppercase version of the string 'hello'
7+
throw new Error('Remove this line and implement the function');
68
};

0 commit comments

Comments
 (0)