[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

nice pattern for running a series of error checks

Martin DeMello

2/22/2008 8:42:00 PM

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

1 Answer

Sylvain Joyeux

2/25/2008 9:47:00 AM

0

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

>