拯救如何进一步提高或忘记例外
rescue how to raise further or forget an exception
如何在埃菲尔铁塔中举起 exception further?我有3个案例
我想重试
a_feature
local
l_retries_count: INTEGER
do
some_potential_failing_feature
rescue
if l_retries_count <= 3 then
l_retries_count := l_retries_count + 1
retry
end
end
我想关闭数据库连接并忽略异常
a_feature
do
some_potential_failing_feature
rescue
db_connection.close
end
我想关闭数据库连接并发送电子邮件给管理员并忽略
a_feature
do
some_potential_failing_feature
rescue
db_connection.close
send_email_to_admin
end
我想关闭db_connection并进一步引发异常,我会把我能想到的所有情况都放在上面的代码中
a_feature
local
l_retries_count: INTEGER
do
some_potential_failing_feature
rescue
if l_retries_count <= 3 then
l_retries_count := l_retries_count + 1
log_error ("Error, retrying for " + l_retries_count.out + "th time")
retry
else
db_connection.close
send_email_to_admin
-- raise the_created_exception_from_some_potential_failing_feature -- how do I do that?
end
end
您可以尝试以下方法之一:
{EXCEPTION_MANAGER}.last_exception.original.raise
{EXCEPTION_MANAGER}.last_exception.cause.raise
{EXCEPTION_MANAGER}.last_exception.raise
第一个经历异常链,忽略那些因例程失败而触发的异常。可能就是您要找的那个。
接下来的两个检索当前异常的原因或当前异常本身,尽管它可能不是您要查找的那个,因为它取决于异常的上下文和嵌套调用。
如何在埃菲尔铁塔中举起 exception further?我有3个案例
我想重试
a_feature local l_retries_count: INTEGER do some_potential_failing_feature rescue if l_retries_count <= 3 then l_retries_count := l_retries_count + 1 retry end end
我想关闭数据库连接并忽略异常
a_feature do some_potential_failing_feature rescue db_connection.close end
我想关闭数据库连接并发送电子邮件给管理员并忽略
a_feature do some_potential_failing_feature rescue db_connection.close send_email_to_admin end
我想关闭db_connection并进一步引发异常,我会把我能想到的所有情况都放在上面的代码中
a_feature local l_retries_count: INTEGER do some_potential_failing_feature rescue if l_retries_count <= 3 then l_retries_count := l_retries_count + 1 log_error ("Error, retrying for " + l_retries_count.out + "th time") retry else db_connection.close send_email_to_admin -- raise the_created_exception_from_some_potential_failing_feature -- how do I do that? end end
您可以尝试以下方法之一:
{EXCEPTION_MANAGER}.last_exception.original.raise
{EXCEPTION_MANAGER}.last_exception.cause.raise
{EXCEPTION_MANAGER}.last_exception.raise
第一个经历异常链,忽略那些因例程失败而触发的异常。可能就是您要找的那个。
接下来的两个检索当前异常的原因或当前异常本身,尽管它可能不是您要查找的那个,因为它取决于异常的上下文和嵌套调用。