#!/usr/bin/perl

use strict;
use warnings;

use lib '../../lib';
use Log::Report;

use Data::Dumper;
$Data::Dumper::Indent = 1;

try { do_delete_all() };
if(my $e = $@)
{
    report {is_fatal=>0}, ERROR => __"Error caught running deletion function, as follows:";
#arn "ERR=$e";
    foreach my $ex ($e->exceptions)
    {   print "EX1 = $ex  ". ($ex->isFatal ? "FATAL" : "REPORT") . "\n";
    }

    $e->reportFatal(is_fatal => 0);
#   print Dumper $@;
}

print "Finished";
exit 0;

sub do_delete_all
{
    my $had_error;
    while (1)
    {
#warn "A";
        error "This error is never seen" if $had_error;
#warn "B";
        try { _delete() };
#warn "C";
        if (my $e = $@)
        {
            report {is_fatal=>0}, ERROR => __"Error deleting message as follows:";
            $e->reportFatal(is_fatal => 0);
            $had_error = 1;
        }
#warn "D";
    }
}

sub _delete
{
    error "error within delete";
}

