>>Is there a way to get the error code and message of the last SQL error?
>>
>>Here's my situation:
>>
>>I call into a method and pass a SQL string which gets dynamically executed in the called method, but if it causes and error (i.e. if it has an invalid SQL syntax or a bad Order By clause), and then when I check AERRORS(), I get the error of the local call to the worker method, rather than the SQL error that I want to discover.
>>
>>I cannot touch the called method code to modify it to handle this, since it is part of another framework that I cannot edit. I must find a way to handle this in my wrapper method.
>>
>>Here is the code I have, but AERRORS() returns info about the call to DoSelect() and not the failure of the SQL statement that I passed in.
>>
>>
>>
>>Try
>> lnReturn = DoSelect(lcSQL)
>>Catch
>> AError(laErrors)
>>
>> If laErrors(1) = 1832
>> This.SetError(This.Class + ' SQL ERROR:' + laErrors(2), laErrors(1))
>> Endif
>>
>> lnReturn = -1
>>Endtry
>>
>
>The only way is to fix DoSelect procedure to return information about the error.
Jim Nelson gave me the answer..
He said:
Catch to loException
loException is an exception object (look it up in help file)
So, now my final code looks like this and works EXACTLY like needed.
Try
lnReturn = DoDefault(lcSelect)
Catch to loException
This.Seterror(This.Class + '.' + loException.Procedure + ':' + loException.Message, loException.ErrorNo)
lnReturn = -1
Endtry