Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:31:43+00:00 2026-06-14T10:31:43+00:00

In a MySQL stored procedure, I am handling SQL exceptions with this: DECLARE EXIT

  • 0

In a MySQL stored procedure, I am handling SQL exceptions with this:

DECLARE EXIT HANDLER FOR SQLEXCEPTION 
    BEGIN
        SELECT "SQL exception occured." AS "SQL Exception";
        SHOW ERRORS;
        SHOW WARNINGS;
        ROLLBACK;
    END;

I know that an exception is being thrown because the SQL exception occured message is being displayed and the transaction gets rolled back. However, nothing is populated in the SHOW ERRORS orSHOW WARNINGS tables. Why is this, and how can I tell which SQL exception is being thrown?

Here is the SQL statement that’s causing the mystery exception:

SELECT IF(count(*) = 0, TRUE, FALSE) 
FROM information_schema.COLUMNS 
WHERE TABLE_SCHEMA='myDatabase' 
AND TABLE_NAME='exam';

EDIT:

Bohemian has informed me that the exception is being swallowed up by the handler. So how do I find out what the exception is and still rollback? In a java catch block, I can see the exception by using Exception.getMessage() or Exception.printStackTrace(). Is there a similar feature in MySQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:31:44+00:00Added an answer on June 14, 2026 at 10:31 am

    When you declare a handler for SQLEXCEPTION, the exception is consumed – it’s considered “handled” so there is no longer an “exception”.

    If your stored procedure flow depends on a particular exception, you must declare a handler for a particular SQLSTATE error code, eg

    DECLARE EXIT HANDLER FOR SQLSTATE `23000`
    

    Actually, all handlers are actually of this form, because:

    • SQLEXCEPTION is shorthand for the class of SQLSTATE values that do not begin with '00', '01', or '02'
    • SQLWARNING is shorthand for the class of SQLSTATE values that begin with '01'
    • NOT FOUND is shorthand for the class of SQLSTATE values that begin with '02'
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
Given this MySQL stored procedure: CREATE PROCEDURE customer.`getCustomers5`( sdf varchar(1000) ) BEGIN set @se
I have a mysql stored procedure from this ( google book ), and one
This has me seriously stumped. I have a MySQL stored procedure that looks like
Possible Duplicate: Mysql - How to quit/exit from stored procedure Is there something equivelant
I'm calling a mysql stored procedure with two input parameters. This is the code
I'm using MYSQL 5.5, How to do Error Handling with Nested Stored Procedure. Pretty
Well I have this MySQL stored procedure that I wrote and if I run
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
I have a MySQL stored procedure like this UPDATE `Discounts` SET `Occupation`=occupation, `Organization`=organization, `LastName`=lastName,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.