Menu

Save/restore condition handler?

Help
cniggeler
2019-11-07
2019-11-07
  • cniggeler

    cniggeler - 2019-11-07

    Hi, I'm creating reusable blocks of code, and in one block I'd like to turn the error handler off (because I'm running 'address system' calls and handle the return codes myself), but at the end would like to restore the error handler. There are two issues that I would appreciate suggestions on:

    1. Is it possible to determine if the caller used "call on error" or "signal on error" so I could correctly use "call on error" or "signal on error" at the end of my code block? (Testing shows that "signal off error" seems to work whether the calling routine used "call" or "signal".)

    2. If there is a handler name (e.g., "signal on error name err"), is it possible to save and restore the name of the condition handler? (I know we could just not use handler names, but there are a couple programs that have two different error condition handlers, so one would need a unique name.)

    Thanks!

     

    Last edit: cniggeler 2019-11-07
  • cniggeler

    cniggeler - 2019-11-07

    After reading condition handling in more detail and with some experimentation, I believe I've answered my own question: Create a string that is the error handler, and then INTERPRET that. Here is a code sample:

    errhand = "call on error name err"
    interpret errhand
    i = 1
    say foo(i)
    address system 'heiaes 2>NUL'
    say bye
    return
    
    foo:
       signal off error
       address system 'heiaes 2>NUL'
       interpret errhand
    return 100*i
    
    err:
       say "error @"SIGL
    return
    

    and the results:
    100
    error @5
    BYE

    Better suggestions would be appreciated.

     

Log in to post a comment.