我正在开发一个小型控制台应用程序。在我的代码中,当出现问题时,有些地方我会抛出自定义的RuntimeExceptions。我正在寻找的是一个全局异常处理程序,可以捕获我的异常并为用户显示正确的信息(也记录它们)。
所以我的想法是在这里使用try-catch:
@SpringBootApplication
public class TfsWorkReporterApplication {
public static void main(String[] args) {
try {
SpringApplication.run(TfsWorkReporterApplication.class, args);
} catch(CustomException ex){
//Display user information.
}
}
}
但是我的第六感告诉我这不是正确的做法。有什么帮助吗?