在 Snowflake 脚本中出现异常后,您可以继续使用 "begin" 子句吗?

Can you continue the "begin" clause after an exception in Snowflake scripting?

在我的“开始”子句中,我使用循环来构建结果集,return。理想情况下,当我遇到异常时,我会在我的结果集中包含一条错误消息。但是,我没有在 Snowflake 脚本或 GOTO 语句中找到任何 try/catch 块的概念。我想我将不得不切换到 Snowflake 脚本和 Python、Javascript 等的混合

BEGIN EXCEPTION END 块可以嵌套在 LOOP 块中。伪代码:

BEGIN
   WHILE ... LOOP
     BEGIN
      ...
     EXCEPTION
         WHEN ... THEN ...
     END;

   END LOOP;
END;

一个简单的例子:

declare
  result varchar;
  my_exception exception (-20001, 'My custom exception.');
begin
  result := 'Success!';
  
  if (true) then
    raise my_exception;
  end if;
  
  return result;
exception
  when my_exception then
    return sqlerrm;
end;

-- returns "My custom exception."

Snowflake 脚本中没有 GOTO 语法