Throwing generic Exception discouraged?

前端 未结 5 526
面向向阳花
面向向阳花 2021-01-04 04:04

Why is it discouraged to throw a generic (java.lang.Exception) exception, when it is usually sufficient to handle most conditional failures within a method? I understand tha

5条回答
  •  走了就别回头了
    2021-01-04 04:36

    Generally you want to know what happened in you app and only catch specific exceptions and let the program fail (or go higher in execution order) when you get the exception that you don't specifically target. Catching Exception will catch them all and in some cases you wouldn't know your program is failing.

提交回复
热议问题