user
Show how to create a user-defined exception   and   show how to catch an exception raised from several nested calls away.

:   1. Create two user-defined exceptions,   **U0**   and   **U1**.
    2. Have function   **foo**   call function   **bar**   twice.
    3. Have function   **bar**   call function   **baz**.
    4. Arrange for function   **baz**   to raise, or throw exception   **U0**   on its first call, then exception   **U1**   on its second.
    5. Function   **foo**   should catch only exception   **U0**,   not   **U1**.

Show/describe what happens when the program is run.
assistant
(formerly Perl 6)

**Translation of**: Perl

```
sub foo() {
    for 0..1 -> $i {
        bar $i;
        CATCH {
            when /U0/ { say "Function foo caught exception U0" }
        }
    }
}

sub bar($i) { baz $i }

sub baz($i) { die "U$i" }

foo;

```

Output:

```
Function foo caught exception U0
U1
  in sub baz at catch:12
  in sub bar at catch:10
  in sub foo at catch:4
  in block  at catch:14
```