[Chicago-talk] error reporting in overridden method

Steven Lembark lembark at wrkhors.com
Tue Sep 21 15:26:22 CDT 2004


> Okay, I have a class that has a method.

All in all, probably a good thing.

> but code duplication is bad.

Take the base class and split out the validation:

	my $result= eval { $obj->execute_foo(@stuff) }
		or die "Unhandled exception in Foo: $@";


	package Foo;

	sub validate_foo
	{
		...

		die "Bogus valiate foo: bar is not given" unless $argz->{bar};

		...
	}

	sub execute_foo
	{
		$_->[0]->validate_foo;

		...
	}


	package MoreFoo;

	use base qw( Foo );

	sub execute_foo
	{
		$_->[0]->validate_foo;

		...
	}





-- 
Steven Lembark                                       85-09 90th Street
Workhorse Computing                                Woodhaven, NY 11421
lembark at wrkhors.com                                     1 888 359 3508


More information about the Chicago-talk mailing list