Reputation: 63
In my "begin" clause I am using a loop to build a resultset and return that. Ideally I would include an error message in my resultset when I encounter an exception. However, I have not found any concept of a try/catch block in Snowflake scripting or a GOTO statement. I think I'm going to have to switch to a mix of Snowflake scripting and Python, Javascript, etc.
Upvotes: 1
Views: 1061
Reputation: 1520
A simple example:
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."
There is no GOTO syntax in Snowflake Scripting
Upvotes: 0
Reputation: 175726
The BEGIN EXCEPTION END block could be nested inside LOOP block. Pseudocode:
BEGIN
WHILE ... LOOP
BEGIN
...
EXCEPTION
WHEN ... THEN ...
END;
END LOOP;
END;
Upvotes: 3