Embedded SQL error handling

Hi Developers!

How do you handle errors with &sql a.k.a. embedded SQL?
I think I found a universal error-handling template which works in any situation:

&sql(SELECT * FROM Sample.Person)

if SQLCODE < 0 throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,"Context description")

What is your choice?

 

Replies

After a lot of troubles around variable scoping in past I try to avoid embedded SQL wherever possible.

I respect your choice. Out of curiosity, what other than SQLCODE variables you noticed being changed "without a warning"?

On contrary, I started to find it handy to copy and paste working sql into &sql(). Also, SQL code looks more readable.

IRIS compiles NOW embedded SQL totally different from Caché / Ensemble.  (extermal Class)
Before you could run in all kind of problems if your host variables were not %*  or declared in the global variable scope.