Hi there-- Am I missing here ?. This is in my second cell. My program has six steps.
I want to exit out when there is no data/filename. Attached is the screenshot of same.
Any hints appreciated…thanks
This means that you should be catching an exception. Just not any
exception. The rule of thumb is that you should catch only what you
expect - other exceptions are “exceptional”, and you want them to get
out so that you can debug their cause.
So put back a try/except in your code, but be much more specific:
from logging import warning
import sys
try:
df = Alteryx.read("#1")
except FileNotFOundError as e:
warning("missing file: %s", e)
sys.exit(1)
The idea is that you should only handle expected situations. Unexpected
stuff need to make noise, otherwise your programme silently proceeds,
usually making nonsense of some kind.
Finally, sys.exit() is ok in a main programme (outside all functions).
Inside a function your almost never want to do that; instead you would
either raise an exception (which you could do by just not catching it)
or returning a special value indicating failure. If the above were in a
function you might return None if you chose that course - naturally
whataver called the function should know what to do with such a thing,
which is why an exception is often a preferred source of action.