You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: courses/ada_essentials/190_exceptions/02-handlers.rst
+36-44Lines changed: 36 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -197,53 +197,45 @@ Exception Handler Content
197
197
Quiz
198
198
------
199
199
200
-
.. container:: latex_environment scriptsize
201
-
202
-
.. container:: columns
203
-
204
-
.. container:: column
205
-
206
-
.. code:: Ada
207
-
:number-lines: 1
208
-
209
-
procedure Main is
210
-
A, B, C, D : Integer range 0 .. 100;
211
-
begin
212
-
A := 1; B := 2; C := 3; D := 4;
213
-
begin
214
-
D := A - C + B;
215
-
exception
216
-
when others => Put_Line ("One");
217
-
D := 1;
218
-
end;
219
-
D := D + 1;
220
-
begin
221
-
D := D / (A - C + B);
222
-
exception
223
-
when others => Put_Line ("Two");
224
-
D := -1;
225
-
end;
226
-
exception
227
-
when others =>
228
-
Put_Line ("Three");
229
-
end Main;
230
-
231
-
.. container:: column
200
+
.. code:: Ada
201
+
:number-lines: 1
202
+
:font-size: footnotesize
232
203
233
-
What will get printed?
204
+
procedure Main is
205
+
A, B, C, D : Integer range 0 .. 100;
206
+
begin
207
+
A := 1; B := 2; C := 3; D := 4;
208
+
begin
209
+
D := A - C + B;
210
+
exception
211
+
when others => Put_Line ("One");
212
+
D := 1;
213
+
end;
214
+
D := D + 1;
215
+
begin
216
+
D := D / (A - C + B);
217
+
exception
218
+
when others => Put_Line ("Two");
219
+
D := -1;
220
+
end;
221
+
exception
222
+
when others =>
223
+
Put_Line ("Three");
224
+
end Main;
234
225
235
-
A. One, Two, Three
236
-
B. :answer:`Two, Three`
237
-
C. Two
238
-
D. Three
226
+
What will get printed?
239
227
240
-
.. container:: animate
228
+
A. One, Two, Three
229
+
B. :answer:`Two, Three`
230
+
C. Two
231
+
D. Three
241
232
242
-
Explanations
233
+
.. container:: animate
243
234
244
-
A. :ada:`One` is never printed, as although :ada:`(A - C)` is not in the range of :ada:`0 .. 100`, this is only checked on assignment (so after the addition of :ada:`B`).
245
-
B. Line 6 does not raise an exception, (so ``One`` is not printed), but Line 2 does - causing ``Two`` to be printed.
246
-
But Line 16 also raises an exception, causing ``Three`` to be printed
247
-
C. If we reach :ada:`Two`, the assignment on line 16 will cause :ada:`Three` to be reached
248
-
D. Divide by 0 on line 13 causes an exception, so :ada:`Two` must be called
235
+
Explanations
249
236
237
+
A. :ada:`One` is never printed. Although :ada:`(A - C)` is not in range, this is only checked on assignment (after addition of :ada:`B`).
238
+
B. No exception on Line 6 (``One`` is not printed), but Line 2 does - so ``Two`` to be printed.
239
+
Line 16 also raises an exception, so ``Three`` to be printed.
240
+
C. If we reach :ada:`Two`, line 16 will cause :ada:`Three` to be reached
241
+
D. Divide by 0 on line 13 causes an exception, so :ada:`Two` must be called
0 commit comments