- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想要在这里破解。我正在尝试的是在抛出异常后执行一些业务逻辑。业务逻辑在 catch block 中定义。我不想将 throw 语句保留在 catch block 的末尾。有什么我可以尝试的技巧吗?我的想法是在该点创建一个线程并在其中抛出异常。我不确定它是否会起作用。请帮帮我。
package demo1.web;
import demo.exceptions.SupportInfoException;
public class TestInnerException {
void testIt() throws Exception{
try{
int i=0;
int j=1/i;
}catch(Exception e){
System.out.println("business logic .. .. . . ");
throw e;
// I want to excute these below line ,
but it is unreachable because you aleready throwing the excetion ..
//any Hacks for it ?
System.out.println("Lines after throwing the exception ... .");
}
System.out.println("I want this logic to be run . . . . .");
}
public static void main(String[] args) throws SupportInfoException, Exception {
TestInnerException t = new TestInnerException();
t.testIt();
}
void testRunTimeEx(){
int i=0;
int j=1/i;
}
}
让我告诉你我的场景,我使用 @ExceptionHandler 注释来处理本文中描述的所有异常。 https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc#user-content-sample-application一些复杂的场景,无法准确解释原因。我在这里想要的是,如果它是由 catch block 处理的,那么我希望在 @ExceptionHandler 中触发它,因为我还有一些其他业务逻辑。问题是除非抛出异常,否则 @ExceptionHandler 不会被触发。我希望它在进入 catch block 时被触发。但如果 catch block 没有抛出任何异常,则不会触发它。
在这种情况下,业务逻辑是指一些日志功能。
最佳答案
这不是黑客,也许没有多大意义。
1) 如果您想抛出
某些异常,请立即抛出
。
2) 如果您想在异常
引发时执行一些业务逻辑,请执行此操作,然后抛出
异常
。
但是如果你想抛出并做一些事情,这里没有任何脏代码是不太可能的。我觉得这里有一股代码味道。
在 question Edit 之后编辑:
虽然是日志记录,但是在抛出之前仍然可以记录日志,抛出之后没有必要生成日志。
关于java - 如何抛出异常并执行 catch block 中的剩余业务逻辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32307256/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我在这里感觉有些不对劲,所以我希望社区提供意见 - 也许我以错误的方式处理这个问题...... 问:是否适合使用传统的基础架构日志框架(如 log4net)来记录业务事件? 当我说业务事件时,我的意思
技术也好,业务也罢; 01 【什么是业务?】 对于那些久经职场的人,也很难一句话说明白; 业务,作为工作中绝对的核心点,即便在一个公司待的足够久,
三天研发,两天设计; 01 【优先做设计方案】 职场中的那些魔幻操作,研发最烦的是哪个? 作为一个数年且资深的互联网普通开发,可以来说明一下为什么
业务、系统、接口(interface)、持久化类是什么意思?用一些例子解释一下? 最佳答案 业务可能是应用程序中所有功能部分发生的部分(即计算或规则) 系统是您的操作系统 接口(interface),
我无法创建带有指向移动应用的外部链接的简单广告。我已正确设置访问权限,可以创建广告系列、广告集、加载图像,但在创建广告期间出现错误: Ads and ad creatives must be asso
我是软件工程专业的学生,现在我正在为我的期末项目工作,安排在交易日进行商务配对。 这个想法是将卖家(开发人员)和买家(有经济能力的人)在一起。 算法应该像“快速约会”。 假设我有 15 张 table
我们只需按照以下说明在 AWS Cloudformation 上部署企业 WhatsApp API: AWS WhatsApp API 所以一切正常,部署正确完成,问题出在“SSL 配置”选项上,我们
我的应用因为以下原因被拒绝了 Guideline 3.2 - Business We found that your app is not appropriate for the App Store
您好,我想在我的网络应用程序中使用 WhatsApp 业务 API。我已经在 postman 中测试过了。 每当在 WhatsApp 选项卡下的 Facebook 业务页面中运行示例 curl 代码时
我是 Skype for Business 技术的新手,我正在尝试部署一个我愿意与 Skype WebSDK 和 AppSDK 一起使用的服务器。 起初我尝试使用Skype进行在线商务,但websdk
Apple 开发人员以此为由拒绝了我的应用。 “业务 - 3.1.1您的应用程序包含一个帐户注册功能,该功能被视为对外部机制的访问,以便在应用程序中使用购买或订阅。此功能不符合 App Store 审
我正在玩 Realm for Android。 我喜欢自动更新对象的想法,但我对它的软件架构有顾虑。 我已经看到许多提议的架构都指定了一个层来处理数据/数据库访问,理想情况下,更高层不会知道有关数据库
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 10 个月前。 Impro
我正在尝试设置 Whatsapp 业务 API。 引用Link用于设置。 我正在使用 Windows 10 操作系统。 -- 仅供引用。 在初始设置部分,使用命令 docker-compose up
我正在尝试使用 Facebook Business SDK 创建一个 facebook Adaccount .但是当我使用方法 createAdAccount 时,它会给我一个错误。请参阅下面的图片。
我想写一个概念证明 MonoMac使用 c# 和 Razor 呈现 html“ View ”的应用程序。 这可能吗? 如果没有,是否有人推荐与 Razor 的简单性相比的任何其他模板引擎。如果必须的话
无法解析 ':business:diary@debug/compileClasspath': Could not resolve project :fun:push. 的依赖关系 无法解析项目:fun
当我尝试在 Visual Studio Professional 2015 14.0.23107.0 中打开某些 XML 文件时,XML 编辑器出现白屏并显示以下文本: 为什么我不能编辑这个文件?此项
我是一名优秀的程序员,十分优秀!