Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c72aad4

Browse files
Create trycatch.js
1 parent 27576f3 commit c72aad4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Javascript/trycatch.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
The getX(x) function returns its parameter x normally under all conditions but throws an error if x equals 5. This must error must be "caught" by the errorHandler() function.
3+
4+
5+
Complete the errorHandler() function such that:
6+
7+
errorHandler() function should call the function getX()
8+
9+
Input to getX() should be x ie. getX(x),
10+
11+
Return the result obtained from getX() function, if error occurs catch and return the error.
12+
*/
13+
14+
function errorHandler(x) {
15+
try{
16+
return getX(x)
17+
}catch(error){
18+
return error;
19+
}
20+
}
21+
22+
function getX(x) {
23+
if(x == 5) {
24+
return new Error("Error Occured");
25+
}
26+
return x;
27+
}
28+
29+
module.exports = errorHandler;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /