#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;   # A handy switch to be aware of

#
# demo of errors and catching them
#
my $x;
my $zero = 0;

# First version : compile time exception
# $x = 1/0;
# print " after first error \n";

# Second version : also compile time exception; is *not* caught
#eval {
#  $x = 1/0;
#  print " after second error \n";
#};
#print "after second error eval block \n";

# Third version : run time exception thrown; same as die()
#$x = 1/$zero;
#print " after third error \n";

# Fourth version : run time exception thrown and caught
eval {
  $x = 1/$zero;
  print " after fourth error \n";
};
print " after fourth error eval block \n";

# After the eval{...} block, $@ is set to the error.
# You can use this to test to see if an error occurred.

print "The value of \$\@ is '" . $@ . "'\n";


