在项目中全局处理未经检查的异常 [英] handling unchecked exceptions globally in project

查看:113
本文介绍了在项目中全局处理未经检查的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一次Java电话采访中,访调员问了一些有关Java异常的问题,其中一个问题是如何在项目中全局处理未经检查的异常。
现在为此,即使我不得不思考一下,通过在Java中定义自定义错误处理程序,但这也不是正确的答案,请您告知我们如何在项目中全局处理未经检查的异常。 p>

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..!

推荐答案

我不是头脑读者,但访问员可能在询问异常处理程序:

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).

这篇关于在项目中全局处理未经检查的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆