Skip to content

Commit 010e4ec

Browse files
committed
add error-handling exercise
1 parent c4e4ed8 commit 010e4ec

File tree

14 files changed

+223
-0
lines changed

14 files changed

+223
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,14 @@
27202720
"practices": [],
27212721
"prerequisites": [],
27222722
"difficulty": 2
2723+
},
2724+
{
2725+
"slug": "error-handling",
2726+
"name": "Error Handling",
2727+
"uuid": "de1c75f2-2461-4347-b5ca-b3cfaafe4d79",
2728+
"practices": [],
2729+
"prerequisites": [],
2730+
"difficulty": 1
27232731
}
27242732
]
27252733
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Instructions
2+
3+
Implement various kinds of error handling and resource management.
4+
5+
An important point of programming is how to handle errors and close resources even if errors occur.
6+
7+
This exercise requires you to handle various errors.
8+
Because error handling is rather programming language specific you'll have to refer to the tests for your track to see what's exactly required.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Error Handling
2+
3+
In this exercise, you will implement a function called `processString` that processes a given input string with proper error handling.
4+
5+
You will learn how to:
6+
7+
- Check input types and handle invalid inputs by throwing errors.
8+
- Throw custom errors for specific cases (e.g., empty strings).
9+
- Use a `try...finally` block to ensure certain code runs regardless of success or failure (such as cleanup or logging).
10+
- Return the uppercase version of the string if it is valid.
11+
12+
Your function should:
13+
14+
- Throw a `TypeError` if the input is not a string.
15+
- Throw an `Error` with the message `EmptyStringError` if the input string is empty.
16+
- Return the uppercase form of the input string if valid.
17+
- Use a `finally` block to log a cleanup message every time the function runs.
18+
19+
This exercise is a great way to practice writing robust functions that can gracefully handle unexpected inputs while always executing necessary cleanup logic.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
/bin/configlet
3+
/bin/configlet.exe
4+
/package-lock.json
5+
/yarn.lock
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"authors": ["Obinna Obi-Akwari"],
3+
"files": {
4+
"solution": [
5+
"error-handling.js"
6+
],
7+
"test": [
8+
"error-handling.spec.js"
9+
],
10+
"example": [
11+
".meta/proof.ci.js"
12+
]
13+
},
14+
"blurb": "Implement various kinds of error handling and resource management."
15+
}

exercises/practice/error-handling/.meta/proof.ci.js

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
audit=false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Exercism
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
presets: [['@exercism/babel-preset-javascript', { corejs: '3.40' }]],
3+
plugins: [],
4+
};

exercises/practice/error-handling/error-handling.js

Whitespace-only changes.

0 commit comments

Comments
 (0)