Search code examples
powerbuilder

Powerbuilder Datawindow "Expression is not valid" cannot be intercepted


When I try to evaluate an expression with describe, it is not possible to catch it in case of an error. For example, in the following code, if the column does not exist, a window with "Expression is not valid" is displayed. I would have expected that an exception would be thrown. try dw.describe("evaluate('columname',1)") catch (DWRuntimeError dwrte) logger.log(dwrte.text) end try


Solution

  • This post doesn't contain any questions so I hope this response is not out of this world.

    Evaluate function used in describe method returns "!" if an error occurs, but it does NOT contain any additional information what the error is, so as far as I am aware you can't intercept (what you described) in the try...catch block.

    What you could possible do is temporarily disable user prompt thus no error messages would pop up to the user and replace try...catch block with if...else block, for example:

    string ls_ret, ls_userprompt    
    
    ls_userprompt = dw.describe("DataWindow.NoUserPrompt")
    
    // user won't see any (error) messages
    dw.modify("DataWindow.NoUserPrompt='Yes'")
    
    ls_ret = dw.describe("evaluate('cc_auftlos', if(auftlos_verg=1, 1, 0))")
    
    if ls_ret = "!" then
        // evaluate not correct
        logger.log("Error text defined by you")
    else
        // evaluate OK, do some processing with the result
    end if
    
    dw.modify("DataWindow.NoUserPrompt='" + ls_userprompt + "'")
    

    Hope this somewhat helps you.