How to catch and re-throw all errors in MySQL

前端 未结 1 593
醉话见心
醉话见心 2021-02-05 05:30

I can\'t seem to find anywhere how to catch and re-throw any errors or warnings that can occur in a procedure.

What I want is the syntax to do the following:

<         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 06:16

    To catch all SQL exceptions, use:

    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    

    SQLWARNINGS can be used to catch warnings also.

    Inside the exception handler, to raise the error or warning that was just caught, use:

    RESIGNAL
    

    See the documentation for the RESIGNAL statement:

    http://dev.mysql.com/doc/refman/5.5/en/resignal.html

    This is available since MySQL 5.5

    0 讨论(0)
提交回复
热议问题