![](/img/trans.png)
[英]Snowflake: How to throw an Exception in the Stored Procedure if the Procedure called inside the Main Procedure doesn't exist or not callable?
[英]Snowflake Stored Procedure Exception & Failure
專家,
對雪花中的異常處理有疑問。 我知道我們可以使用 try & catch 塊來處理錯誤並使用 return/throw 錯誤消息。
如果有問題,請告訴我。
拋出將生成一個新錯誤或將現有錯誤發送到堆棧中。 如果您使用 try/catch 塊並“返回”有關錯誤的信息,則您要離開的函數將不會指示錯誤情況。 它可能會發送有關錯誤的信息,但由於代碼捕獲了錯誤,因此如果堆棧上沒有任何內容捕獲它,它就不會向上堆棧並可能終止執行。
當您從 Snowflake UI 運行 JavaScript UDF 或存儲過程時,您可以判斷存在未捕獲的錯誤,因為返回值以紅色返回。 如果錯誤以黑色或藍色返回,即使錯誤消息報告錯誤,它也已被捕獲並且調用的狀態不是錯誤。 下面是一個例子:
create or replace procedure FOO()
returns string
language javascript
as
$$
// Run a helper function here
myFunction();
function myFunction(){
var mySqlStatement = "select * from NONEXISTENT_TABLE";
var statement1 = snowflake.createStatement({sqlText: mySqlStatement});
statement1.execute();
}
$$;
call foo(); // This will generate an error and return in red text.
create or replace procedure FOO()
returns string
language javascript
as
$$
try{
myFunction();
}
catch(e){
return e.message;
}
function myFunction(){
var mySqlStatement = "select * from NONEXISTENT_TABLE";
var statement1 = snowflake.createStatement({sqlText: mySqlStatement});
statement1.execute();
}
$$;
call foo();
// This will catch an error and return it in blue text.
//External clients will not report an error, even through the
//SP returns the error message.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.