try ... catch ?

enzo

New Member
Hello, this code:

DEFINE VARIABLE hc AS HANDLE NO-UNDO.
RUN "libcont" PERSISTENT SET hc NO-ERROR.



Show the error : ** CRC for index <indexname> on table <tablename> ... Try recompiling. (7968)

if I recompile the .p then the error is fixed, but I want to catch the message error. Is possible that?

thanks.
 

rzr

Member
I'm may not be fully correct, but i think this error cannot be "caught". It is always recommended that all / affected source files be recompiled on every schema change.
 

Stefan

Well-Known Member
See Progress Knowledge Base.

But a work-around seems to be available on PSDN - note that a RUN of a non-existent .p also raises a STOP condition, which is what I think the CRC is also raising:

Code:
DO ON ERROR UNDO, LEAVE ON STOP UNDO, LEAVE:
    OUTPUT TO "NUL:" KEEP-MESSAGES.
    RUN nonexistent.p.
    OUTPUT CLOSE.
END.
 

jmac13

Member
I've been looking for this...

I cant seem to get the error to output to a file:

Code:
define variable Chrfilename as character no-undo.

    Chrfilename =   session:temp-directory + chrProgram + ".Txt".                                     
                           
    output stream ostream to value(Chrfilename).                                            
                                                 

DO ON ERROR UNDO, LEAVE ON STOP UNDO, LEAVE:
    OUTPUT TO ostream KEEP-MESSAGES.
    RUN nonexistent.p.
    OUTPUT CLOSE.
    output stream ostream close.      
END.


can you throw the stop and catch it or is the only way to deal with running missing stuff?

cheers
 

RealHeavyDude

Well-Known Member
Maybe something like this will help ( at least a little bit and please be aware it's coded in Firefox IDE ... ): You can't catch a STOP or QUIT condition with the "new" structured error handling, as far as I know, but you can use some kind of work around to handle a STOP condition like this
SOME-BLOCK:
DO ON ERROR UNDO SOME-BLOCK, LEAVE SOME-BLOCK
ON STOP UNDO SOME-BLOCK, RETRY SOME-BLOCK:

IF RETRY THEN DO:
/* You have encountered a STOP condition ... */
END.

CATCH ....:

END CATCH.

END.

Heavy Regards, RealHeavyDude.
 

jmac13

Member
I've been looking for this...

I cant seem to get the error to output to a file:

Code:
define variable Chrfilename as character no-undo.

    Chrfilename =   session:temp-directory + chrProgram + ".Txt".                                     
                           
    output stream ostream to value(Chrfilename).                                            
                                                 

DO ON ERROR UNDO, LEAVE ON STOP UNDO, LEAVE:
    OUTPUT TO ostream KEEP-MESSAGES.
    RUN nonexistent.p.
    OUTPUT CLOSE.
    output stream ostream close.      
END.


can you throw the stop and catch it or is the only way to deal with running missing stuff?

cheers
 

rzr

Member
you should see the error in log file now:
Code:
DEFINE VARIABLE Chrfilename AS CHARACTER NO-UNDO.

DEFINE STREAM ostream.

ASSIGN Chrfilename =   session:temp-directory + "RZR" + ".Txt".

OUTPUT STREAM ostream TO VALUE(Chrfilename) KEEP-MESSAGES.
DO ON ERROR UNDO, LEAVE ON STOP UNDO, LEAVE:
    RUN nonexistent.p.
END.
OUTPUT STREAM ostream CLOSE.
 

rzr

Member
to answer the original question - as suggested by Stefan & RHD earlier...
the same logic that i wrote above will also capture and redirect the CRC error to log file
 

Stefan

Well-Known Member
can you throw the stop and catch it or is the only way to deal with running missing stuff?

As mentioned in the PSDN thread, no. You unfortunately cannot CATCH a STOP condition. RUNning a non-existent file raises a STOP condition. Which is why you can / need to use the work-around.
 

RealHeavyDude

Well-Known Member
But you could still roll your own and throw your own application specific exception which will then be caught be the next outer catch for application errors. But that just extends the workaround and does not solve the underlying issue - which is IMHO - that we need to mix and match procedural with OO approach and they sometimes don't work together smoothly out-of-the-box. The block based error handling ( if you want to call it so ) has been in the language as long as I can think back ( which would be V6, beginning of the 1990s ), whereas the structured error handling is a "brand new" add-on.

Heavy Regards, RealHeavyDude.
 

enzo

New Member
Thanks for reply me Stefan,jmac13,RealHeavyDude,rzr. Both codes dont raise the error message,
but ERROR-STATUS:ERROR returns false and is not possible get the progress error-message. Try Catch dont exist.

These portions of code seems the best solution possible.

thanks.
 

UncleNel

New Member
Here is a sample of simple structured error handling that I used to catch a server issue when opening file that would not be captured using the error-status. Maybe this would help your case. Good luck.

procedure Open_Stream:
def var cMsg as char no-undo.

do transaction on error undo,THROW:
output stream sZerosList to
value( cDestDir + cFileName + cTodayYMD + ".log" )
append /*unbuffered*/ .

/*Structured Error Handling*/
CATCH eSysError AS Progress.Lang.SysError:
assign cMsg = eSysError:GetMessage(1).
delete object eSysError.
return ERROR cMsg.
END CATCH.

end.
end procedure.
 

TomBascom

Curmudgeon
Here is a sample of...

"CODE" tags make this kind of thing a whole lot more readable:

Code:
procedure Open_Stream:

   def var cMsg as char no-undo.

   do transaction on error undo, THROW:

     output stream sZerosList to value( cDestDir + cFileName + cTodayYMD + ".log" ) append /*unbuffered*/ .

     /*Structured Error Handling*/
     CATCH eSysError AS Progress.Lang.SysError:
       assign  cMsg   = eSysError:GetMessage(1).
       delete object eSysError.
       return ERROR cMsg.
     END CATCH.

   end.

end procedure.
 
Top