我正在尝试更多地了解基本Java和不同类型的Throwables,有人能告诉我异常和错误之间的区别吗?
我的工作流程在使用 try-catch 失败时发送邮件。我还启用了并发性,这样,当同一工作流程的多个作业进入限制阶段时,新作业会取消旧作业。这会引发异常"org.jenkinsci.plugins.workflow.steps.FlowInterruptedException"并取消作业也会触发邮件通知。
现在我修改了我的工作流程以捕获特定的FlowInterruptedException异常并抑制邮件通知并让其他任何事情触发邮件,就像这样。
node {
try {
// some stages for the workflow
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e){
echo "the job was cancelled or aborted"
}
catch (err){
stage 'Send Notification'
mail (to: 'adminj...@somename.com',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) has had an error.",
body: "Some text",
mimeType:'text/html');
currentBuild.result = 'FAILURE'
}
}
Run Code Online (Sandbox Code Playgroud)
这仅捕获FlowInterruptedException并且当作业由于任何其他原因(命令拼写错误等)而真正失败时,我期望它将被其他捕获捕获并触发其中的代码来发送邮件。但事实并非如此。
我认为我的代码在 try catch 中存在一些缺陷。任何想法?
更新:
以防万一,如果我使用下面的代码,它只会发送邮件以解决任何失败
node {
try {
// some stages for the workflow
}
catch (err){
stage 'Send Notification' …Run Code Online (Sandbox Code Playgroud)