MySQL Forums
Forum List  »  Stored Procedures

Re: error handling - what happens if you don't know the error number !
Posted by: Roland Bouman
Date: January 06, 2006 01:24PM

> I am trying to determine the best replacement for
> the following :
>
> MS SQL Server equivalent:
>
>
> If @@error = 0 then ........

mmm, according to http://msdn2.microsoft.com/en-us/library/ms188790(en-us,VS.90).aspx, @@error=0 is equivalent to know error having occurred. In MySQL, execution just continues. It will temporarily stop, transferring control to a handler, in case an error actually does occur. So, no literl equivalent.

Q: for what type of problem is @@error=0 a solution? I thought the idea is that you handle the exceptional event of an error occurring - not the event of everything being, well, normal.

>
> I need to know how I can create such a GENERAL
> error handler in MySQL.
>
> Now from what I have read:
>
> 1. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
> BEGIN END;
>
> refer:
> http://dev.mysql.com/doc/refman/5.0/en/declare-han
> dlers.html
>
> condition_value:
> SQLSTATE sqlstate_value
> | condition_name
> | SQLWARNING
> | NOT FOUND
> | SQLEXCEPTION
>
>
> the examples I have all read all use error
> handling and refer to SPECIFIC error numbers.
>
> The other problem I have is that if I was to use:
>
> DECLARE CONTINUE HANDLER FOR SQLEXCEPTION;
>
> this will only work when the error does not fall
> under "warning", "not found" see above link
>

The actual syntax recipe sais:

DECLARE handler_type HANDLER FOR condition_value[,...] statement

So, you can include a *LIST* of conditions:

DECLARE CONTINUE HANDLER FOR
SQLEXCEPTION
, SQLWARNING
, NOT FOUND
BEGIN
...
END;

would handle pretty much everything.

Good luck, Roland.

BTW, if you want to find out inside your general handler what the actual condition was, you're out of luck. See:

http://bugs.mysql.com/bug.php?id=11660

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: error handling - what happens if you don't know the error number !
1456
January 06, 2006 01:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.