Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果发生异常,并且它在 catch 块中被捕获,但不会被抛出。框架有没有办法知道有异常?
背景(为什么):我们必须重新制作以前的项目并添加异常处理。但是,许多异常并没有被抛出。
非常感谢!
//for example private void handle() { try{ int i = 5/0; }catch(Throwable e){ ;//here the e is not throwed } }
这也许是可以实现的,但并非没有黑客攻击。例如,您可以使用 AspectJ 向Throwable构造函数提供将注册异常实例化事件的代码。这与实际抛出它们不同,但它是一个很好的近似值。关键优势在于,使用这种方法,您只有一个可以干预的地方。
Throwable
请注意,使用这种方法肯定会产生很多噪音,因为在许多地方(包括 JDK 本身)都合法地抛出并在本地捕获异常。