Try/Catch inside or outside functions

后端 未结 5 1741
温柔的废话
温柔的废话 2021-01-02 13:02

I have a very basic question about best practice of using try/catch. I have a simple function (DAO) like this

public void addVehicl         


        
5条回答
  •  生来不讨喜
    2021-01-02 13:13

    You should only catch those exceptions which you want to handle. You may include a topmost exception handler to turn any unhandled exceptions into something somewhat useful for the end user.

    Instead of e.printStackTrace();, try return proper exception message.

    find out more about exception handling here

    Here is more discussion about exception handling.

提交回复
热议问题