Skip to content

Commit 717eb56

Browse files
committed
lite: Add TryExcept examples
1 parent 7565a3d commit 717eb56

File tree

1 file changed

+249
-0
lines changed

1 file changed

+249
-0
lines changed

lite/contents/TryExcept.ipynb

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"*** Settings ***\n",
10+
"\n",
11+
"Documentation Robot Framework 5 syntax examples.\n",
12+
"\n",
13+
"Library IPython.display # Provides Display-keyword"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"*** Test Cases ***\n",
23+
"TRY / EXCEPT: Catch any exception\n",
24+
" TRY\n",
25+
" Fail\n",
26+
" EXCEPT\n",
27+
" Display EXCEPT with no arguments catches any exception.\n",
28+
" END"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"*** Test Cases ***\n",
38+
"\n",
39+
"TRY / EXCEPT: Catch an exception by exact message\n",
40+
" TRY\n",
41+
" Fail Error message\n",
42+
" EXCEPT Error message\n",
43+
" Display Catches only \"Error message\" exceptions.\n",
44+
" Display Enables error-specific exception handling.\n",
45+
" END"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"*** Test Cases ***\n",
55+
"\n",
56+
"TRY / EXCEPT: Multiple EXCEPT statements\n",
57+
" TRY\n",
58+
" Fail Error message\n",
59+
" EXCEPT Another error message\n",
60+
" Display Catches only \"Another error message\" exceptions.\n",
61+
" EXCEPT Error message\n",
62+
" Display Catches the \"Error message\" exception.\n",
63+
" END"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"*** Test Cases ***\n",
73+
"\n",
74+
"TRY / EXCEPT: Multiple messages in EXCEPT statement\n",
75+
" TRY\n",
76+
" Fail CCC\n",
77+
" EXCEPT AAA BBB CCC\n",
78+
" Display Catches any \"AAA\", \"BBB\", or \"CCC\" exception.\n",
79+
" END"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"*** Test Cases ***\n",
89+
"\n",
90+
"TRY / EXCEPT: Catch a specific exception, or an unexpected exception\n",
91+
" TRY\n",
92+
" Fail Error message\n",
93+
" EXCEPT Another message\n",
94+
" Display Catches only \"Another message\" exceptions.\n",
95+
" EXCEPT\n",
96+
" Display Catches any exception.\n",
97+
" Display Useful for handling unexpected exceptions.\n",
98+
" END"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": null,
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"*** Test Cases ***\n",
108+
"\n",
109+
"TRY / EXCEPT: Catch exceptions where the message starts with\n",
110+
" TRY\n",
111+
" Fail A long error message with lots of details\n",
112+
" EXCEPT A long error message type=start\n",
113+
" Display Matches the start of an error message.\n",
114+
" END"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"*** Test Cases ***\n",
124+
"\n",
125+
"TRY / EXCEPT: Capture the error message\n",
126+
" TRY\n",
127+
" Fail Goodbye, world!\n",
128+
" EXCEPT AS ${error_message}\n",
129+
" Display ${error_message} # Goodbye, world!\n",
130+
" END"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": null,
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"*** Test Cases ***\n",
140+
"\n",
141+
"TRY / EXCEPT: Using ELSE when no exceptions occured\n",
142+
" TRY\n",
143+
" Display All good!\n",
144+
" EXCEPT Error message\n",
145+
" Display An error occured.\n",
146+
" ELSE\n",
147+
" Display No error occured.\n",
148+
" END"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": null,
154+
"metadata": {},
155+
"outputs": [],
156+
"source": [
157+
"*** Test Cases ***\n",
158+
"\n",
159+
"TRY / EXCEPT / FINALLY: Always execute code no matter if exceptions or not\n",
160+
" TRY\n",
161+
" Display All good!\n",
162+
" FINALLY\n",
163+
" Display FINALLY is always executed.\n",
164+
" END\n",
165+
" TRY\n",
166+
" Fail Catastrophic failure!\n",
167+
" EXCEPT\n",
168+
" Display Catches any exception.\n",
169+
" FINALLY\n",
170+
" Display FINALLY is always executed.\n",
171+
" END"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": null,
177+
"metadata": {},
178+
"outputs": [],
179+
"source": [
180+
"*** Test Cases ***\n",
181+
"\n",
182+
"TRY / EXCEPT / ELSE / FINALLY: All together!\n",
183+
" TRY\n",
184+
" Fail Error message\n",
185+
" EXCEPT\n",
186+
" Display Executed if any exception occurs.\n",
187+
" ELSE\n",
188+
" Display Executed if no exceptions occur.\n",
189+
" FINALLY\n",
190+
" Display FINALLY is always executed.\n",
191+
" END"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": null,
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"*** Test Cases ***\n",
201+
"\n",
202+
"TRY / EXCEPT: Glob pattern matching\n",
203+
" TRY\n",
204+
" Fail My error: 99 occured\n",
205+
" EXCEPT My error: * type=glob\n",
206+
" Display Catches by glob pattern matching.\n",
207+
" END\n",
208+
" "
209+
]
210+
},
211+
{
212+
"cell_type": "code",
213+
"execution_count": null,
214+
"metadata": {},
215+
"outputs": [],
216+
"source": [
217+
"*** Test Cases ***\n",
218+
"\n",
219+
"TRY / EXCEPT: Regular expression matching\n",
220+
" TRY\n",
221+
" Fail error 99 occured\n",
222+
" EXCEPT [Ee]rror \\\\d+ occured type=regexp\n",
223+
" Display Catches by regular expression pattern matching.\n",
224+
" END"
225+
]
226+
}
227+
],
228+
"metadata": {
229+
"kernelspec": {
230+
"display_name": "Robot Framework",
231+
"language": "robotframework",
232+
"name": "Robot Framework"
233+
},
234+
"language_info": {
235+
"codemirror_mode": {
236+
"name": "robotframework",
237+
"version": 3
238+
},
239+
"file_extension": ".robot",
240+
"mimetype": "text/x-robotframework",
241+
"name": "robotframework",
242+
"nbconvert_exporter": "robotframework",
243+
"pygments_lexer": "robotframework",
244+
"version": "3.8"
245+
}
246+
},
247+
"nbformat": 4,
248+
"nbformat_minor": 4
249+
}

0 commit comments

Comments
 (0)