Skip to content
Advertisement

Snowflake procedure not getting caught by catch block

Why does my snowflake procedure in javascript produces an error and not getting caught by the catch block?

I have a very simple procedure created like this, instead of this going into catch and logging the error it is returning JAVASCRIPT UNCAUGHT exception.

Can someone help? Here is the code:

CREATE OR REPLACE PROCEDURE TEST()
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
AS
$$
    var CorrectSQL  =` SELECT COL1, COL2 FROm TABLE_1  LIMIT 10`;
    var InCorrectSQL  =` SELE COL1, COL2 FROm TABLE 2  LIMIT 10`; // SYNTAX ERROR SELE 
    var InsertIntoErrorLog =` INSERT INTO ERROR_LOG VALUES ('ERROR')`;
    try
{
    snowflake.execute({sqlText:CorrectSQL}); 
    snowflake.execute({sqlText:InCorrectSQL}); 
}
  catch(err)
{
    snowflake.execute({sqlText: InsertIntoErrorLog});
    return err;
}
$$

Advertisement

Answer

Actually, it works as expected. You have “return err;” command at the end, this is why it returns the error message. Try this one:

CREATE OR REPLACE PROCEDURE TEST()
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
AS
$$
  var CorrectSQL  = `SELECT COL1, COL2 FROm TABLE_1  LIMIT 10`;
  var InCorrectSQL  = `SELE COL1, COL2 FROm TABLE_2  LIMIT 10`;
  var InsertIntoErrorLog =`INSERT INTO ERROR_LOG VALUES ('ERROR')`;
  try {
        snowflake.execute({sqlText:CorrectSQL }); 
       snowflake.execute({sqlText:InCorrectSQL }); 
   } catch (err) {
        snowflake.execute({sqlText: InsertIntoErrorLog});
       // return err;
    }
$$;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement