From f960c404aa67e36dcb20287ac2c61f494df4e602 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sun, 13 Jul 2014 23:40:39 -0500 Subject: [PATCH] separate c++ from c error handling --- CXX/yapi.cpp | 7 +++---- CXX/yapi.hh | 12 +++++++----- CXX/yapie.hh | 32 ++++++++++---------------------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 381003bfa..535505744 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -379,7 +379,7 @@ YAPPredicate::YAPPredicate(const char *s, Term **outp, term_t &vnames) throw (in vnames = Yap_NewSlots(1 PASS_REGS); Term t = Yap_StringToTerm(s, strlen(s)+1, vnames); if (t == 0L) - throw SYNTAX_ERROR; + throw YAPError::YAP_SYNTAX_ERROR; ap = getPred( t, outp ); //{ CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__, "OUT vnames=%d ap=%p LCL0=%p", vnames, ap, LCL0) ; } } @@ -575,7 +575,6 @@ displayWithJava(int c) Yap_AndroidBufp[Yap_AndroidSz] = '\0'; if (c == '\n' ) { Yap_AndroidBufp[Yap_AndroidSz] = '\0'; - __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, "after char %c:%s %p",c, Yap_AndroidBufp, curren); curren->run(Yap_AndroidBufp); Yap_AndroidSz = 0; } @@ -636,8 +635,8 @@ YAPQuery *YAPEngine::safeQuery( char *s ) { n->resetFlag( PL_Q_PASS_EXCEPTION ); return n; } - catch (yap_error_number errno) { - error = errno; + catch (YAPError yerr) { + yerror = yerr; return 0; } } diff --git a/CXX/yapi.hh b/CXX/yapi.hh index 972be7313..68888e9b9 100644 --- a/CXX/yapi.hh +++ b/CXX/yapi.hh @@ -59,6 +59,8 @@ extern "C" { #include "YapText.h" +#include "yapie.hh" + #if HAVE_STDARG_H #include #endif @@ -421,7 +423,7 @@ public: Term t, tp; t = YAP_ReadBuffer(s,&tp); if (t == 0L) - throw SYNTAX_ERROR; + throw YAPError::YAP_SYNTAX_ERROR; ap = getPred( t, (Term **)NULL ); } @@ -433,7 +435,7 @@ public: Term t, tp; t = YAP_ReadBuffer(s,&tp); if (t == 0L) - throw SYNTAX_ERROR; + throw YAPError::YAP_SYNTAX_ERROR; ap = getPred( t, (Term **)NULL ); } @@ -551,7 +553,7 @@ class YAPEngine { private: YAPCallback *_callback; YAP_init_args init_args; - yap_error_number error; + YAPError yerror; public: YAPEngine(char *savedState = (char *)NULL, size_t stackSize = 0, @@ -575,12 +577,12 @@ public: void run() { if (_callback) _callback->run(); } /// execute the callback with a text argument. void run( char *s) { if (_callback) _callback->run(s); } + /// execute the callback with a text argument. + YAPError hasError( ) { return yerror; } /// build a query on the engine YAPQuery *query( char *s ); /// build a query on the engine handling exceptions YAPQuery *safeQuery( char *s ); - - yap_error_number hasError( ); //> report whether the engine has found an error }; /* diff --git a/CXX/yapie.hh b/CXX/yapie.hh index 4cacd1ec6..00d9741c3 100644 --- a/CXX/yapie.hh +++ b/CXX/yapie.hh @@ -10,27 +10,15 @@ class YAPPredicate; class YAPError { public: - static const int SYNTAX_ERROR = 0x10000; //> syntax error - static const int DOMAIN_ERROR = 0x20000; //> usually illegal parameter, like asin( 2 ) - static const int TYPE_ERROR = 0x40000; //> usually illegal parameter in the language, like ( 2 mod 3.0 ) - static const int PERMISSION_ERROR = 0x80000; //> wrong para,eter - static const int EVALUATION_ERROR = 0x100000; //> bad arithmetic expressions - static const int RESOURCE_ERROR = 0x200000; //> no resource available, like MEM - static const int REPRESENTATION_ERROR = 0x400000; //> bad UTF-8 strings, etc - static const int EXISTËNCE_ERROR = 0x400000; //> object not found - static const int PROFILER = 0x400000; //> improve profiling support. - static const int OTHER_ERROR = 0x800000; //> anything rldr.,,,,,,,,,,,,,,,,,,,, -}; - -class YAPErrorClass { -public: - static const int SYNTAX_ERROR = 0x10000; - static const int DOMAIN_ERROR = 0x20000; - static const int TYPE_ERROR = 0x40000; - static const int PERMISSION_ERROR = 0x80000; - static const int EVALUATION_ERROR = 0x100000; - static const int RESOURCE_ERROR = 0x200000; - static const int REPRESENTATION_ERROR = 0x400000; - static const int OTHER_ERROR = 0x800000; + static const int YAP_SYNTAX_ERROR = 0x10000; //> syntax error + static const int YAP_DOMAIN_ERROR = 0x20000; //> usually illegal parameter, like asin( 2 ) + static const int YAP_TYPE_ERROR = 0x40000; //> usually illegal parameter in the language, like ( 2 mod 3.0 ) + static const int YAP_PERMISSION_ERROR = 0x80000; //> wrong para,eter + static const int YAP_EVALUATION_ERROR = 0x100000; //> bad arithmetic expressions + static const int YAP_RESOURCE_ERROR = 0x200000; //> no resource available, like MEM + static const int YAP_REPRESENTATION_ERROR = 0x400000; //> bad UTF-8 strings, etc + static const int YAP_EXISTENCE_ERROR = 0x800000; //> object not found + static const int YAP_PROFILER = 0x100000; //> improve profiling support. + static const int YAP_OTHER_ERROR = 0x2000000; //> anything };