handling unchecked exceptions globally in project [closed]

99封情书 提交于 2019-12-13 10:27:05

问题


I an an telephonic interview of java the interviewer asked few questions regarding java exceptions in which one of the question he asked is How can you handle unchecked exceptions globally in project.? now for this even i have to think for a moment by defining the custom error handler in java but this was not the correct answer , can you please advise how we can handle the unchecked exceptions globally in project..!


回答1:


I am not a mind reader, but the interviewer was probably asking about exception handlers:

  • You can set a global handler by calling the static method Thread.setUncaughtExceptionHandler, or
  • You can set a thread-specific handler by calling setUncaughtExceptionHandler on the individual thread, or
  • If you are in a thread group, you can override ThreadGroup.uncaughtException() method (ThreadGroup implements the UncaughtExceptionHandler interface).



回答2:


You can set UnCaughtExceptionHandler per Thread probably your interview was looking it to handle for main Thread

Thread.setUnCaughtExceptionHandler()



来源:https://stackoverflow.com/questions/25696642/handling-unchecked-exceptions-globally-in-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!