Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Having a catchall exception may seem like a bad idea to some, but I am quite often in situations where I write code that I really don't want to fail (and I want it to continue running). Fore these cases I always used it as such:

    try:
        result = somethingrisky()
    except SomeKnownException as e:
        return handle_known_error(e)
    except Exception as e:
        log_error(e)
        return None
    return result
    
or something among those lines. And this is perfectly fine if that risky function e.g involves requests that in my experience can fail for a ton of reasons and it is hard to know them all.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: