Does re.compile() or any given Python library call throw an exception?

后端 未结 2 1499
夕颜
夕颜 2020-12-18 19:59

I can\'t tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that coul

2条回答
  •  清歌不尽
    2020-12-18 20:36

    Unlike Java, where there are exceptions that must be declared to be raised (and some that don't have to be, but that's another story), any Python code may raise any exception at any time.

    There are a list of built-in exceptions, which generally has some description of when these exceptions might be raised. Its up to you as to how much exception handling you will do, and if you will handle stuff gracefully, or just fail with a traceback.

提交回复
热议问题