One thing I often struggle with is how to deal with exceptions, especially when I have a chain of functions that use each others output and/or long running processes. As the answer will probably be "it depends" take for example this program flow:

open a file and read into BytesIO buffer
get a FTP connection from pool
send buffer to plantuml.jar in memory FTP server
render file to image
get image from FTP server
push the image onto CherryPy bus
push (SSE) the image to web browser

def read_file(input_file):
    try:
        with open(input_file, 'rb') as f:
            buffer = io.BytesIO(f.read())
    except FileNotFoundError as e:
        print(e)
        ....
    return buffer

assume the file is not found, I cannot just kill the whole process. Catching the exception is one thing, but how to deal with it properly, I have to inform the client somehow what went wrong.

In this case I could push the error message into the returned buffer and just go from there and the image will show the message.

I could also bypass the whole process somehow and push the error message directly on the CherryPy bus.

What is wisdom, are there some general rules to follow in such cases

ingo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to