# Exception.pm --- Sample exception class
# Reference: 
# http://www.perl.com/pub/a/2002/11/14/exception.html 

package Exception;

# The following is equivalent to 
# use Error; @ISA = ('Error');
use base "Error"; 

# Operator overloading --- so that simple error message
# is displayed on string interpolation of error object
use overload ('""' => 'stringify');

sub new {
	my $this = shift;
	my $msg = shift;
	my $soln = shift;

	local $Error::Debug = 1;	# enable stacktrace

	# Ensure correct discovery of position where error object thrown
	# Needed because overriding of constructor
	local $Error::Depth = $Error::Depth + 1;

	$this->SUPER::new(-text => $msg, -soln => $soln);
}

# Show solution, if any
sub solution {
	my $this = shift;
	return $this->{'-soln'};
}

1;
