What is the best way to catch an IllegalArgumentException

后端 未结 4 2617
星月不相逢
星月不相逢 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 11:47

    You should not handle an IllegalArgumentException. It's porpose is to inform the developer, that he have called a method with wrong arguments. Solution is, to call the method with other arguments.

    If you must catch it you should use

    catch(IllegalArgumentException e)
    

提交回复
热议问题