error handling

This commit is contained in:
Vitor Santos Costa 2018-03-24 22:56:52 +00:00
parent 0b67a66533
commit e02884a94f
2 changed files with 40 additions and 40 deletions

View File

@ -437,6 +437,7 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
LOCAL_RestartEnv = &buf; LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) { if (sigsetjmp(*LOCAL_RestartEnv, false)) {
std::cerr << "Restart\n"; std::cerr << "Restart\n";
throw *new YAPError();
//q.e = new YAPError(); //q.e = new YAPError();
} }
// don't forget, on success these bindings will still be there); // don't forget, on success these bindings will still be there);
@ -490,7 +491,7 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
if (sigsetjmp(*LOCAL_RestartEnv, false)) { if (sigsetjmp(*LOCAL_RestartEnv, false)) {
// PyEval_RestoreThread(_save); // PyEval_RestoreThread(_save);
std::cerr << "Restart\n"; std::cerr << "Restart\n";
//throw new YAPError(); throw *new YAPError();
} }
// don't forget, on success these guys may create slots // don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -567,10 +568,7 @@ Term YAPEngine::fun(Term t) {
sigjmp_buf buf, *oldp = LOCAL_RestartEnv; sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
LOCAL_RestartEnv = &buf; LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) { if (sigsetjmp(*LOCAL_RestartEnv, false)) {
// throw new YAPError(); throw *new YAPError();
LOCAL_RestartEnv = oldp;
RECOVER_MACHINE_REGS();
return 0;
} }
// don't forget, on success these guys may create slots // don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -693,7 +691,7 @@ bool YAPQuery::next() {
return false; return false;
LOCAL_RestartEnv = &buf; LOCAL_RestartEnv = &buf;
if (sigsetjmp(*LOCAL_RestartEnv, false)) { if (sigsetjmp(*LOCAL_RestartEnv, false)) {
//e = new YAPError(); throw *new YAPError();
} }
// don't forget, on success these guys may create slots // don't forget, on success these guys may create slots
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
@ -712,9 +710,8 @@ bool YAPQuery::next() {
} }
q_state = 1; q_state = 1;
if ((terr = Yap_PeekException())) { if ((terr = Yap_PeekException())) {
LOCAL_RestartEnv = &buf; throw * new YAPError();
result = false;
} }
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);

View File

@ -144,20 +144,20 @@ class YAPShell:
# if not isinstance(eq[0],str): # if not isinstance(eq[0],str):
# print( "Error: Variable Name matches a Python Symbol") # print( "Error: Variable Name matches a Python Symbol")
# return # return
self.do_ask = True try:
engine = self.engine engine = self.engine
bindings = [] bindings = []
loop = False
g = python_query(self, query) g = python_query(self, query)
if not self.q: if not self.q:
self.q = Query( engine, g ) self.q = Query( engine, g )
for bind in self.q: for bind in self.q:
bindings += [bind] bindings += [bind]
if self.do_ask: if loop:
print(bindings) continue
bindings = [] if not self.q:
break
s = input("more(;), all(*), no(\\n), python(#) ?").lstrip() s = input("more(;), all(*), no(\\n), python(#) ?").lstrip()
else:
s = ";"
if s.startswith(';') or s.startswith('y'): if s.startswith(';') or s.startswith('y'):
continue continue
elif s.startswith('#'): elif s.startswith('#'):
@ -166,7 +166,7 @@ class YAPShell:
except: except:
raise raise
elif s.startswith('*') or s.startswith('a'): elif s.startswith('*') or s.startswith('a'):
self.do_ask = False loop = True
continue continue
else: else:
break break
@ -176,6 +176,9 @@ class YAPShell:
return True,bindings return True,bindings
print("No (more) answers") print("No (more) answers")
return False, None return False, None
except e:
print("Exception")
print(e)
def live(self, engine, **kwargs): def live(self, engine, **kwargs):