title: Declare error handler not valid in MySQL?
body: <p>I'm trying to write my first stored procedure that uses an error handler, but It doesn't seem to accept my syntax. Here's what I'm using:</p>
  
  <pre><code>DELIMITER //
  
  CREATE PROCEDURE min_list_valid (OUT pass CHAR
                                  ,OUT errs VARCHAR(50)
                                  ,IN `@list_id` INT
                                  ,IN `@min_input` INT)
  BEGIN
      BEGIN
          DROP TABLE IF EXISTS `errors_table`;
          CREATE TEMPORARY TABLE `errors_table`(error VARCHAR(30))ENGINE=MEMORY;
      END;
  
      BEGIN
          DECLARE error_holder VARCHAR(30);
          DECLARE error_checker VARCHAR(30);
          SET error_checker = 0;
  
          DECLARE CONTINUE HANDLER FOR SQLSTATE, SQLEXCEPTION
          BEGIN
              SELECT 'The user input is less than the minimum for this list' INTO error_holder;
              SELECT error_holder INTO `errors_table`;
              SET error_checker = 1;
          END;
  
          SELECT      IF(MAX(CAST(`peg_num` AS UNSIGNED))&lt;`@min_input`,'pass',NULL) AS `key`
          FROM        `game_lists`
          WHERE       `list_id` = `@list_id`
          INTO        pass;
  
          IF error_checker &lt;&gt; 0 THEN
              SELECT * FROM `errors_table`
          END IF;
      END;
  END; //
  </code></pre>
  
  <p>It gives me back the error message:</p>
  
  <p><code>#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE CONTINUE HANDLER FOR SQLSTATE, SQLEXCEPTION BEGIN ' at line 16</code></p>
  
  <p>But that's strange, it's telling me the declare is wrong but the line in error is line 16 (the one with <code>SET error_checker = 0</code>). I believe I'm following the correct syntax so... what's wrong?</p>
  
  <p>What this stored proc just does is select some maximum value from a list, and everything else is just me trying to create an error handler and an error table to store the generated errors. I wanted to try a simple functionality first with the "full blown" error handling so there's not too many debug points.</p>
  
  <p>My MySQL version is 5.6.14 - MySQL Community Server (GPL)</p>