About error handling when developing PEPPER apps A summary of how to handle it in PythonBox.
This is a diversion article from our Utage Blog.
http://utage.headwaters.co.jp/blog/?p=4656
When an error occurs in PythonBox In case of an unhandled error, the application will terminate immediately.
Currently, if the robot is forcibly terminated, It seems to the user that it ended suddenly without any warning, so Be sure to handle it and tell the user.
In case of an error detected by Choregraphe, The box in which the error occurred turns red. This is also the case for SyntaxError and so on.
There are several ways to handle errors in PythonBox, so I will explain those methods.
Like error handling in general Python You can handle the error by writing it with try: except :.
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
pass
def onUnload(self):
pass
def onInput_onStart(self):
try:
raise Exception, "Raise Error."
except Exception as e:
self.log(str(e))
def onInput_onStop(self):
self.onUnload()
self.onStopped()
In the above example, it's just spitting logs, I can't cover anything, but it's the process I'm doing in try The app will not crash even if an exception occurs.
In the case of actual use, I think that it will be used more often as follows.
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
pass
def onUnload(self):
pass
def onInput_onStart(self):
try:
#Processing that can cause an error
self.onSucceeded()
except Exception:
self.onFailed()
def onInput_onStop(self):
self.onUnload()
self.onStopped()
By changing the output when raised as above You can handle errors in PythonBox.
Added onError output on the edit screen of Box
If you do this It will be output from the onError output when an exception occurs in PythonBox.
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
pass
def onUnload(self):
pass
def onInput_onStart(self):
raise Exception, "Raise Error."
def onInput_onStop(self):
self.onUnload()
self.onStopped()
Also, by setting the Type of onError to a character string, Arguments such as the error message of raised Exception can be output as a character string.
Recommended Posts