nice pattern for running a series of error checks

Discussion in 'Ruby' started by Martin DeMello, Feb 22, 2008.

  1. 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
     
    Martin DeMello, Feb 22, 2008
    #1
    1. Advertising

  2. 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

    >
     
    Sylvain Joyeux, Feb 25, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anders K. Jacobsen [DK]

    "Pattern" or "best practice" in security checks

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Johann MacDonagh
    Dec 6, 2004
  2. Mark Fanty
    Replies:
    8
    Views:
    346
    Mark Fanty
    Jan 25, 2005
  3. rock826
    Replies:
    0
    Views:
    323
    rock826
    Oct 8, 2007
  4. rock826

    Nice small game to play at work - Series 1

    rock826, Oct 8, 2007, in forum: C Programming
    Replies:
    0
    Views:
    648
    rock826
    Oct 8, 2007
  5. Anders K. Jacobsen [DK]

    "Pattern" or "best practice" in security checks

    Anders K. Jacobsen [DK], Dec 5, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    146
    Anders K. Jacobsen [DK]
    Dec 5, 2004
Loading...

Share This Page