SnowConvert AI - SQL Server-Azure Synapse - CONTINUE HANDLER¶
Description¶
In SQL Server and Azure Synapse Analytics, exception handling is primarily managed through TRY...CATCH blocks. Unlike some other database systems (such as Teradata or DB2), SQL Server does not have a native DECLARE CONTINUE HANDLER statement.
However, when migrating code from other database systems that use CONTINUE HANDLERs, SnowConvert AI transforms these constructs into equivalent Snowflake Scripting exception handling mechanisms.
A CONTINUE HANDLER in the source system allows execution to continue after an error occurs, performing specific actions when certain conditions are met. In Snowflake, this is achieved using EXCEPTION blocks with conditional logic.
For more information about SQL Server error handling, see TRY…CATCH (Transact-SQL).
Grammar Syntax¶
SQL Server does not have native CONTINUE HANDLER syntax. However, when converting from other database systems, the source pattern typically looks like:
Sample Source Patterns¶
CONTINUE HANDLER Conversion from DB2/Teradata¶
When migrating stored procedures from DB2 or Teradata that contain CONTINUE HANDLER declarations, SnowConvert AI transforms them into Snowflake-compatible exception handling.
Input Code:¶
Source (DB2/Teradata Pattern)¶
Output Code:¶
Snowflake Scripting¶
CONTINUE HANDLER with SQLEXCEPTION¶
Input Code:¶
Source (DB2/Teradata Pattern)¶
Output Code:¶
Snowflake Scripting¶
Known Issues¶
Limited CONTINUE HANDLER Support¶
Applies to
SQL Server
Azure Synapse Analytics
SQL Server’s native TRY...CATCH mechanism does not have an exact equivalent to CONTINUE HANDLER. When an error occurs in a TRY block, control immediately passes to the CATCH block, and execution does not continue from the point of error.
SnowConvert AI attempts to emulate CONTINUE HANDLER behavior in Snowflake, but there are limitations:
Execution Flow: True CONTINUE HANDLER behavior (continuing from the exact point of error) cannot be fully replicated.
Statement-level Wrapping: Individual statements may need to be wrapped in separate exception blocks.
Performance: Multiple nested exception blocks can impact performance.
Known Issues¶
When migrating CONTINUE HANDLER patterns from other database systems through SQL Server to Snowflake, be aware that exception handling behavior may differ. The TRY…CATCH pattern in SQL Server is converted to Snowflake’s EXCEPTION blocks, but semantic differences may exist. Thorough testing is recommended to ensure the converted code maintains the intended behavior.
SQLWARNING and NOT FOUND Conditions¶
Applies to
SQL Server
Azure Synapse Analytics
CONTINUE HANDLERs for SQLWARNING and NOT FOUND conditions require special handling in Snowflake:
SQLWARNING: Snowflake does not distinguish between warnings and errors in the same way as source systems.
NOT FOUND: Typically used for cursor operations or SELECT INTO statements that return no rows.
Example¶
Source Pattern¶
Snowflake¶
Best Practices¶
When working with converted CONTINUE HANDLER code:
Review Exception Handling: Verify that the converted exception handling logic matches the intended behavior.
Test Error Scenarios: Thoroughly test error conditions to ensure the application behavior is correct.
Consider Refactoring: In some cases, refactoring the error handling logic may provide better performance and maintainability.
Use Transactions: Leverage Snowflake’s transaction support to ensure data consistency.