Throwing Correct Error in Predicates

Fernando Ribeiro, created Jan 25. 2015 I am writing a library with predicates to communicate ActiveMQ with Jekejeke Prolog. When a connection can't be created, for example, I am throwing the following error: InterpreterMessage.domainError("Can't create connection", new TermRef(connFactory)) Is that what a "domain" error is supposed to be used for, or should a different "category" of error be used instead?

Comments

Re: Throwing Correct Error in Predicates

Jan Burse, created Jan 27. 2015 Hi, Maybe you noticed already. If you want to wrap a Java exception thrown by a foreign Java method by yourself, you can do this by creating an InterpreterMessage and throw this. The interpreter will then create an InterpreterException from this InterpreterMessage by adding a back trace from the current predicate call. If you want that your exception shows more than a message and a stack trace, you have to create InterpreterException by yourself from the beginning, you can then for example add a line number and text offset. In some cases the interpreter might also create the InterpreterMesssage for you. You can just pass the Java exception from the foreign Java method. This is a feature that exists since release 1.0.4 of the Jekejeke Runtime. Java exceptions such as UnsupportedEncodingException, MalformedURLException, etc.. are currently recognized. You find the current list here, might add more exceptions in the future: http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/10_docu/02_reference/07_theories/06_reflect/03_foreign.html It is also best when you leave the InterruptedException exception to the interpreter. This Java exception indicates that the current thread has been interrupted by another thread. The other thread can be a GUI thread, for example the Ctrl-. command in Swing or the Abort Menu Item in Android. Or the other thread can be a system thread, for example the memory low detector in Swing. The cause of the interruption is stored in the signal field of in the interpreter. Either you should rethrow the interrupted exception or clear and read the signal, and throw the signal. The interpreter will follow the later scenario for you. Bye

Re: Throwing Correct Error in Predicates

Fernando Ribeiro, created Jan 26. 2015 I will go with system errors this time. Thanks!

Re: Throwing Correct Error in Predicates

Jan Burse, created Jan 26. 2015 Jekejeke Prolog has internally an error message internationalization system. But this feature is not yet public. So when you throw an error term <fun>(<arg1>, ...,<argn>) you should use for <fun> and those <argi> that are not culprits, non end-user texts but some atoms you define. In a future release you will be able to provide Germen, English, etc.. end-user texts for each atoms combination. So better throw for the moment: InterpreterMessage.domainError("create_failed", new TermRef(connFactory)) So use a neutral atom create_failed, instead the final text. Please be patient till the API to configure the error texts will be published in one of the next releases. The API exists already and is quite simple, you only have to add some .property files to your code. Bye P.S.: Instead of domain error, type error, use better permission error, resource error or existence error or some custom ball. Use system error for fatal errors, since it cannot be catched via catch/3 by the end-user and might exit the interpreter.