Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.


I m new in sql anywhere 12 database. I cant find out how to catch error inside stored procedure.

In MSSQL I use


-- code to do


-- code to log error and return error message to client


How to do something similar in sql anywhere 12 stored procedure? I m using T-SQL syntax.

Thx Tomaz

asked 22 Dec '12, 10:11

tomazs's gravatar image

accept rate: 0%

permanent link

answered 22 Dec '12, 13:12

AlexeyK77's gravatar image

accept rate: 8%

I try to use example from help but this is not generic error handling. If I get it right is needed to declare error type before executing code? Is it posible that server return message what kind of error happend inside BEGIn END?

(24 Dec '12, 06:30) tomazs
permanent link

answered 22 Dec '12, 15:18

Breck%20Carter's gravatar image

Breck Carter
accept rate: 20%

Thx. This work only if I select Watcom-sql but I want to write procedures in Transact SQL. I could probably check SQLSTATE or SQLCODE aftter every statment but this is what we do yeas ago :0))

(24 Dec '12, 06:23) tomazs

TSQL in SA oly for compatibility with ASE. ASE as I know don't support try/catch blocks.

(24 Dec '12, 07:03) AlexeyK77

Aha, so is it better switch to Watcom SQL? I stuck on first procedure :0)) so not lot to recreate.

(24 Dec '12, 07:20) tomazs
Replies hidden

Yes... I think everyone here will agree that Watcom SQL is a much improved syntax... more features, especially.

(24 Dec '12, 10:12) Breck Carter

Yes, watcom SQL much better than tsql.

(24 Dec '12, 11:06) AlexeyK77

Just a few more hints:

  • I fully agree with Breck and Alexey that Watcom-SQL is the recommended SQL dialect within SQL Anywhere - and note that you can declare several EXCEPTION clauses within one SQL block, so you can use structured exception handling - similar to using several catch blocks in PLs like C++/Java/C#. In contrast, T-SQL's TRY/CATCH just allows for one CATCH block per TRY block.

  • However, if you want/have to be compatible to other DBMSs like ASE or MS SQL Server, using T-SQL code is usually possible in SQL Anywhere. For T-SQL code, you may have a look at the on_tsql_error option and that comparison.

  • If MS-SQL compatibility is a strong requirement, and if you like to get familiar with SQL Anywhere but don't need a productive solution in the very near future, you may also consider having a look at the SQL Anywhere 16 beta called "Nagano". I can't tell whether there is support for something like a TRY/CATCH construct there - but you may check for yourself.

permanent link

answered 27 Dec '12, 03:51

Volker%20Barth's gravatar image

Volker Barth
accept rate: 34%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 22 Dec '12, 10:11

question was seen: 9,109 times

last updated: 27 Dec '12, 03:51