Java Best way to throw exception in a method

前端 未结 3 1896
误落风尘
误落风尘 2021-01-26 00:28

I have created my own type of exception and want to implement it in a method. As of now I have written it in the following way, and it works.

public Worker remov         


        
3条回答
  •  广开言路
    2021-01-26 00:49

    I'm not going to comment on whether or not to use checked vs unchecked exceptions as that will provoke a monster debate.

    If you create a checked exception, then yes it must be thrown in the method signature. If you create an unchecked e.g. extends from RuntimeException then you do not need to throw it in the method signature.

    Checked exceptions are generally exceptions that are recoverable. Unchecked exception are irrecoverable.

提交回复
热议问题