Throws or try-catch

后端 未结 10 1369
别跟我提以往
别跟我提以往 2020-11-28 03:15

What is the general rule of thumb when deciding whether to add a throws clause to a method or using a try-catch?

From what I\'ve read mysel

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 03:49

    try-catch pair is used when you want to provide customise behaviour, in case if exception occurs.....in other words...you have a solution of your problem (exception occurrence) as per your programme requirements.....

    But throws is used when you don't have any specific solution regarding the exception occurrence case...you just don't want to get abnormal termination of your programme....

    Hope it is correct :-)

提交回复
热议问题