example howto handle Exceptions in shell

This commit is contained in:
Kamil Sopko
2016-03-10 16:01:50 +01:00
parent 4f2f989bdf
commit 6b527fa256

View File

@@ -644,14 +644,32 @@ class App(QtCore.QObject):
else:
self.defaults['stats'][resource] = 1
class TclErrorException(Exception):
"""
this exception is deffined here, to be able catch it if we sucessfully handle all errors from shell command
"""
pass
def raiseTclUnknownError(self, unknownException):
"""
raise Exception if is different type than TclErrorException
:param unknownException:
:return:
"""
if not isinstance(unknownException, self.TclErrorException):
self.raiseTclError("Unknown error: %s" % str(unknownException))
def raiseTclError(self, text):
"""
this method pass exception from python into TCL as error, so we get stacktrace and reason
:param text: text of error
:return: raise exception
"""
self.tcl.eval('return -code error "%s"' % text)
raise Exception(text)
raise self.TclErrorException(text)
def exec_command(self, text):
"""
@@ -660,6 +678,7 @@ class App(QtCore.QObject):
:param text: Input command
:return: None
"""
self.report_usage('exec_command')
text = str(text)
@@ -2659,6 +2678,8 @@ class App(QtCore.QObject):
:param args: array of arguments
:return: "Ok" if completed without errors
'''
try:
a, kwa = h(*args)
types = {'outname': str}
@@ -2698,6 +2719,9 @@ class App(QtCore.QObject):
except Exception as e:
self.raiseTclError("Failed: %s" % str(e))
except Exception as unknown:
self.raiseTclUnknownError(unknown)
return 'Ok'
def isolate(name=None, *args):