Skip to content

Commit 8b218eb

Browse files
itsAlifitsAlif
itsAlif
authored and
itsAlif
committed
Solved catch block problem
1 parent 283faff commit 8b218eb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines 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)