异常处理反模式 [英] Exception-handling antipatterns

查看:189
本文介绍了异常处理反模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常处理对于新的和有经验的开发人员来说是一个挑战。什么是例外处理反模式的例子,人们看到了?

Exception handling is a challenge for new and experienced developers alike. What are some examples of exception handling antipatterns that people have seen?

推荐答案

这是一个不完全不同于我'以前看过。

Here's one that isn't entirely unlike things that I've seen before.

try {
    methodThatThrowsSomeException1();
    methodThatThrowsSomeOtherException2();
    methodThatThrowsSomeOtherException3();
    methodThatThrowsSomeOtherException4();
    methodThatThrowsSomeOtherException5();
    methodThatThrowsSomeOtherException6();
    ...
    methodThatThrowsYetAnotherException20();
} catch (Throwable e) {
    log.error("There was a problem reading the user role");
    role = PRIVILEGED;
}

这篇关于异常处理反模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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