What is the best way to catch an IllegalArgumentException

后端 未结 4 2630
星月不相逢
星月不相逢 2021-02-20 11:02

When would be the best use of this type of exception and is it handeled properly if caught in a catch like so?

catch(Exception e)

Or does it ne

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-20 12:01

    You should stay away from catch (Exception) since that way you'll catch every possible exception. If you really only expect the IllegalArgumentException and handle that case you shouldn't broaden that scope; better add more catch blocks for other types of exceptions, then.

提交回复
热议问题