【发布时间】:2021-10-28 03:13:34
【问题描述】:
我正在实现一个引发错误的表单验证函数。这些异常会冒泡并在我的应用程序中的更高级别上进行管理:
this.form.inputs.forEach(input => {
if (input.required && !input.value) {
throw new AppError({ customMessage: new Notification(notificationTypes.Error, `${input.label} not filled`)});
}
})
事情是抛出异常停止函数执行,所以我只能捕捉到第一个错误。
有什么建议吗?我的想法不多了:(
【问题讨论】:
-
不是立即抛出,而是收集所有异常,只有在函数结束后才抛出它们的集合?
标签: javascript exception error-handling throw