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

Appearance settings

Commit 8b218eb

Browse filesBrowse files
itsAlifitsAlif
itsAlif
authored and
itsAlif
committed
Solved catch block problem
1 parent 283faff commit 8b218eb
Copy full SHA for 8b218eb

File tree

1 file changed

+15
-0
lines changed
Filter options

1 file changed

+15
-0
lines changed

‎src/13-catch-blocks.solution.3.ts

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, it } from "vitest";
2+
3+
const tryCatchDemo = (state: "fail" | "succeed") => {
4+
try {
5+
if (state === "fail") {
6+
throw new Error("Failure!");
7+
}
8+
} catch (e) {
9+
return (e as Error).message;
10+
}
11+
};
12+
13+
it("Should return the message when it fails", () => {
14+
expect(tryCatchDemo("fail")).toEqual("Failure!");
15+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.