|
Trap examples (VIP 6.x)This is an example of how to handle some errors: clauses ... trap(openXFile(XFile), E, openXFile_trap_handler(E)), ... openXFile_trap_handler(error_fileDoesNotExist):- !, cErrorSystem::clear(), % handle "file does not exist". openXFile_trap_handler(error_fileReadOnly):- !, cErrorSystem::clear(), % handle "file is read only". openXFile_trap_handler(Exitcode):- % some exits are not handled here send them on cErrorSystem::continue(...). A handler which ensures that a lock is released looks as follows predicates xxx_trap_handler(integer Exitcode) – erroneous (i) clauses xxx_trap_handler(_):- releaseLock(), fail. xxx_trap_handler(Exitcode):- cErrorSystem::continue(...). In this situation we have used a bullet proof construction with fail: We are certain that the error will be continued, whether releaseLock fails or not. If releaseLock is a procedure, then a single clause will be sufficient. |