Let us start with one of the simplest exceptions, division by zero. Run the following one-liner:
say 1 / 0;
The program breaks and prints the following error message:
Attempt to divide 1 by zero using div in block <unit> at zero-div.pl line 1 Actually thrown at: in block <unit> at zero-div.pl line 1
We cannot divide by zero. Notice that the error message also contains the stack trace of the program. As we do not use any modules or have any function calls, the stack trace is short.
Now, let's do some other actions before and after the line with the division, which fails:
say 'Going to divide 1 by 0'; say 1 / 0; say 'Division is done';
An exception because of division by zero happens at runtime. So, the program executes the first line and prints the first message. Then, an exception occurs and the program terminates. Nothing...