Nice pattern for running a series of error checks

came up with this while refactoring some code:

case
when test_1; report_error test_1
when test_2; report_error test_2
when test_3; report_error test_3
else; do_success

the nice thing is that it automatically exits the structure at the
first failing test.

martin

On Sat, Feb 23, 2008 at 05:42:28AM +0900, Martin DeMello wrote:

case
when test_1; report_error test_1
when test_2; report_error test_2
when test_3; report_error test_3
else; do_success

the nice thing is that it automatically exits the structure at the
first failing test.

Well. The preferred way to report error should be raising exceptions, in
which case everything up to the nearest error handler is exited at the
first failing test…

Sylvain