Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit c39bad8

Browse files
committed
adding examples for promises that support try/catch for exceptions
1 parent 500cceb commit c39bad8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

examples/02 - callbacks/callbacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
def py_random():
99
return random.random()
1010

11+
@eel.expose
12+
def py_exception(error):
13+
if error:
14+
raise ValueError("Test")
15+
else:
16+
return "No Error"
17+
1118
def print_num(n):
1219
print('Got this from Javascript:', n)
1320

examples/02 - callbacks/web/callbacks.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,25 @@
2020

2121
// Do the same with an inline callback
2222
eel.py_random()(n => console.log('Got this from Python: ' + n));
23-
23+
24+
// show usage with promises
25+
// show no error
26+
eel.py_exception(false)().then((result) => {
27+
// this will execute since we said no error
28+
console.log("No Error")
29+
}).catch((result) => {
30+
console.log("This won't be seen if no error")
31+
}
32+
);
33+
// show if an error occurrs
34+
eel.py_exception(true)().then((result) => {
35+
// this will not execute
36+
console.log("No Error")
37+
}).catch((result) => {
38+
console.log("This is the repr(e) for an exception " + result.errorText);
39+
console.log("This is the full traceback:\n" + result.errorTraceback);
40+
}
41+
)
2442
</script>
2543
</head>
2644

0 commit comments

Comments
 (0)