一个 'when' 子句可以处理 oracle 中的多个异常类型吗?
Can a single 'when' clause handle multiple exception types in oracle?
假设我有如下程序:
PROCEDURE proc_name (args)
IS
-- declarations
...
BEGIN
-- code
...
EXCEPTION
WHEN an_error THEN
--error handling code
....
WHEN another_error THEN
-- error handling code, identical to the one for an_error
...
WHEN others THEN
---generic error handling code`
....
END;
理想情况下,我希望能够在同一个 WHEN 子句中捕获 an_error
和 another_error
,因为它们的处理是相同的。
这在 Oracle 中可行吗?如果不是,还有什么其他的方法可以避免代码重复?
是的,你可以。
您可以在异常之间使用 OR 条件,所以
EXCEPTION
WHEN an_exception
OR another_exception
THEN
handle it here;
END;
有关异常处理的更多详细信息,请参阅 The Docs。
假设我有如下程序:
PROCEDURE proc_name (args)
IS
-- declarations
...
BEGIN
-- code
...
EXCEPTION
WHEN an_error THEN
--error handling code
....
WHEN another_error THEN
-- error handling code, identical to the one for an_error
...
WHEN others THEN
---generic error handling code`
....
END;
理想情况下,我希望能够在同一个 WHEN 子句中捕获 an_error
和 another_error
,因为它们的处理是相同的。
这在 Oracle 中可行吗?如果不是,还有什么其他的方法可以避免代码重复?
是的,你可以。
您可以在异常之间使用 OR 条件,所以
EXCEPTION
WHEN an_exception
OR another_exception
THEN
handle it here;
END;
有关异常处理的更多详细信息,请参阅 The Docs。