Path: utzoo!attcan!uunet!wuarchive!sdd.hp.com!uakari.primate.wisc.edu!uflorida!haven!mimsy!mimsy.umd.edu!alberto From: alberto@cs.umd.edu (Jose Alberto Fernandez R) Newsgroups: comp.lang.prolog Subject: Re: error handling (was about arg/3) Message-ID: Date: 25 Oct 90 17:45:49 GMT References: <1328@n_kulcscs.kuleuven.ac.be> <1804@ecrc.de> Sender: news@mimsy.umd.edu Organization: University of Maryland Computer Sc. Lines: 51 In-reply-to: micha@ecrc.de's message of 25 Oct 90 10:55:20 GMT In article <1804@ecrc.de> micha@ecrc.de (Micha Meier) writes: I'm still not sure if this approach is better than nothing at all or not. exit_block/1 can of course be used to catch the error somewhere in the top-level loop, emit an error message and abort. The question is, why such a complicated mechanism to get so little? The problem with exit_block/1 is that you have to have a corresponding block/3 call in order to catch it, and so if you want to something different that just abort, you'd have to wrap every call you expect may make an error into a block/3. So, e.g. if you want an undefined procedure to fail, you would write instead of p(X) block(p(X), Something, fail) in *all* places where p/1 might be undefined. One can hardly imagine something more awkward. I have discussed this in my NACLP'89 paper about events. The problem with this is that we are looking at only two extremes. Silent fail, the user can't distinguis between good fail and error, and exceptions, the program is aborted and the exception can be catched by some handler. I propose a more simple and flexible mechanism that has been used already in Prolog. The mechanism used by print-portray. The idea is that when an error occurs intead of fail, produce an exception o send a message, the code calls a predicate error_handler/1 defined by the user. If the call to error_handler fails, then the default is performed (i.e. write error message or rise exception) otherwise the clause is executed and after that the predicate fails silently. With this mechanism the user can control each predicate separately if he prefers silent on non silent failure. If the user whan to rise a exception he can call exit_block in its code. You can also provide with libraries for cprolog behavior of Quintus or whatever you whant. Any comments. Jose Alberto. -- :/ \ Jose Alberto Fernandez R | INTERNET: alberto@cs.umd.edu :| o o | Dept. of Computer Sc. | BITNET: alberto@cs.umd.edu :| ^ | University of Maryland | UUCP: {...}!mimsy!alberto :\ \_/ / College Park, MD 20742 |