工作流错误处理
如果在执行工作流期间发生错误,则会引发异常。如果异常未由工作流自身所捕获(或者如果工作流引发的异常未以其他方式捕获),则工作流将失败,并向用户显示有关异常的信息。要正确处理错误,应该捕获并处理异常。例如,在前面的示例中,尝试在不存在的项目中创建共享资源会导致未捕获的异常。示例 22工作流错误处理
此示例可以修改以捕获违例错误,并在项目不存在的情况下创建该项目:var workflow = {
name: 'Create share',
description: 'Creates a new share in a business unit',
parameters: {
name: {
label: 'Name of new share',
type: 'String'
},
unit: {
label: 'Business unit',
type: 'ChooseOne',
options: [ 'development', 'finance', 'qa', 'sales' ],
optionlabels: [ 'Development', 'Finance',
'Quality Assurance', 'Sales/Administrative' ],
}
},
execute: function (params) {
try {
run('shares select ' + params.unit);
} catch (err) {
if (err.code != EAKSH_ENTITY_BADSELECT)
throw (err);
/*
* We haven't yet created a project that corresponds to
* this business unit; create it now.
*/
run('shares project ' + params.unit);
run('commit');
run('shares select ' + params.unit);
}
run('filesystem ' + params.name);
run('commit');
return ('Created new share "' + params.name + '"');
}
};