Error handling in PythonBox

Overview

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

Error handling method

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.

ss1.png

There are several ways to handle errors in PythonBox, so I will explain those methods.

  1. try, except

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.

2. Use standard PythonBox features

Added onError output on the edit screen of Box

ss2.png

ss3.png

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

Error handling in PythonBox
[Error handling] peewee.IntegrityError 1451 occurs in peewee
Mainframe error handling
Error in random.shuffle
Python Error Handling
Error in Pyinstaller
SikuliX error handling
Error in TensorBoard
django.db.migrations.exceptions.InconsistentMigrationHistory error handling
About tweepy error handling
Handling json in python
Hexadecimal handling in Python 3
GraphQL (gqlgen) error handling
Around feedparser error handling
zipimporter error in pyramid
How to install poetry (error handling) in zsh environment
[Error countermeasures] django-heroku installation error handling
About FastAPI ~ Endpoint error handling ~
Multiprocessing error in Jupyter Notebook
Handling of quotes in [bash]
Handling sparse matrices in Scipy
Slice error in python (´ ; ω ; `)
PyCUDA build error handling memorandum
Relative url handling in python
Solver Problem Error in poetry
Error divided by 0 Handling of ZeroDivisionError
Handling of JSON files in Python
Handling timezones in Python (datetime, pytz)
An error occurred in scikit-learn imputer
Fix setuptools missing error in anaconda
Error handling when updating Fish shell
How to suppress display error in matplotlib
Handling of character code of file in IronPython
The story of an error in PyOCR
In pip install clang: error: unknown argument:'-mno-fused-madd'
Error handling during Django migrate'DIRS': [BASE_DIR /'templates']
[Illegal hardware instruction python] error in PyMC3
Resolve the Address already in use error
I'm saving in UTF-8 but Syntax Error
Dictionary key error → Resolve with key in dicionary
Solution for run-time error in OpenVINO IEPlugin.load ()
Sample for handling eml files in Python
Module import and exception handling in python
Import Error in Python3: No module named'xxxxx'