How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the EchoLisp 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 EchoLisp 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 EchoLisp programming language
Source code in the echolisp programming language
(define (foo)
(for ((i 2))
(try
(bar i)
(catch (id message)
(if (= id 'U0)
(writeln message 'catched)
(error id "not catched"))))))
(define (bar i)
(baz i))
(define (baz i)
(if (= i 0)
(throw 'U0 "U0 raised")
(throw 'U1 "U1 raised")))
(foo) →
"U0 raised" catched
👓 error: U1 not catched
You may also check:How to resolve the algorithm Largest number divisible by its digits step by step in the Crystal programming language
You may also check:How to resolve the algorithm Cuban primes step by step in the Ring programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Sierpinski triangle/Graphical step by step in the Asymptote programming language
You may also check:How to resolve the algorithm Binary strings step by step in the J programming language