MySQL 5.7 GetDiagnostics is always returning null for SQLSTATE What am I doing wrong? I have the following Handler and the sqlexception is being caught, but GET DIAGNOSTICS is not returning any information - they are all NULL. 

I have the following code:

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  BEGIN 

      GET DIAGNOSTICS @cno = NUMBER;
      GET DIAGNOSTICS CONDITION @cno @errno = MYSQL_ERRNO;

      GET DIAGNOSTICS CONDITION 1
        currentcode = RETURNED_SQLSTATE, msg = MESSAGE_TEXT;

    GET CURRENT DIAGNOSTICS CONDITION 1 @current = RETURNED_SQLSTATE;
    GET STACKED DIAGNOSTICS CONDITION 1 @stacked = RETURNED_SQLSTATE;

  SELECT @current, @stacked, @errno INTO currentcode,stackedcode,errorcode;


GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
SELECT @full_error;

CALL debug_msg(1,@full_error);

    SET _rollback = 1;  
    SET ResultCode = CONCAT('currentcode: ' , currentcode, ' , stackedcode: ' , stackedcode);
  END;


I admit that the condition_number element - I do not understand if it represents the index of conditions that were caught or if it is the error number to look at and the documentation on the MySQL site says condition_number (ok I get that it is a condition_number.)
Replace GET DIAGNOSTICS CONDITION 1 

with GET STACKED DIAGNOSTICS CONDITION 1

In my case this helped me.