0

I'm hoping this isn't just duplicating this question.

I have read the documentation but I don't think I fully understand how to use this properly yet.

I would like to catch errors thrown in my stored procedures and log those errors in a table. This is mostly for experimental purposes. I am wondering is there a way to catch any error and then log the code and error to a table.

So far it looks like I have to declare a different handler for each error. Is this correct or is there a way to catch all errors and get the code and message.

For example in each stored procedure I'm declaring a couple of handlers

DECLARE EXIT HANDLER FOR 1062
BEGIN
    SELECT 'Attempt to create a duplicate entry occurred';
END;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SELECT 'Unexpected Error Ocurred';
END; 

Instead of

 SELECT 'custom message'; 

I want to do

INSERT INTO errorLogs(code, message);

Is this possible without declaring a load of handlers and adding each code manually?

Really appreciate any help pointing me in the right direction.

1 Answer 1

0

It looks like this is not really possible until I can use an updated version of MYSQL with DIAGNOSTICS. I found this question which is basically the same as mine. Ah well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.