How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Eiffel programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Eiffel programming language
Table of Contents
Problem Statement
Show how to create a user-defined exception and show how to catch an exception raised from several nested calls away.
Show/describe what happens when the program is run.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Eiffel programming language
Source code in the eiffel programming language
class MAIN
inherit EXCEPTIONS
creation foo
feature {ANY}
baz_calls: INTEGER
feature foo is
do
Current.bar
rescue
if is_developer_exception_of_name("U0") then
baz_calls := 1
print("Caught U0 exception.%N")
retry
end
if is_developer_exception then
print("Won't catch ")
print(developer_exception_name)
print(" exception...%N")
end
end
feature bar is
do
Current.baz
end
feature baz is
do
if baz_calls = 0 then
raise("U0")
else
raise("U1")
end
end
end
You may also check:How to resolve the algorithm Hilbert curve step by step in the C programming language
You may also check:How to resolve the algorithm Lah numbers step by step in the Julia programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the Stata programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Lua programming language
You may also check:How to resolve the algorithm First-class functions step by step in the Quackery programming language