[英]rescue how to raise further or forget an exception
如何在埃菲爾進一步提出異常? 我有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
我想關閉數據庫連接並將 email 發送給管理員並忽略
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
第一個通過異常鏈忽略因例程失敗而觸發的異常。 它可能是您正在尋找的那個。
接下來的兩個檢索當前異常的原因或當前異常本身,盡管它可能不是您要查找的,因為它取決於異常的上下文和嵌套調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.