|
Trap examples (VIP 5.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):- !, % handle "file does not exist". openXFile_trap_handler(error_fileReadOnly):- !, % handle "file is read only". openXFile_trap_handler(Exitcode):- % some exits are not handled here send them on exit(Exitcode). 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):- exit(Exitcode). 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. |