MySQL - How to throw exception in stored procedure?
Since MySQL 5.5 you can use SIGNAL and RESIGNAL for error handling. Prior to that there was no way to handle errors in MySQL. Only way is to run an erroneous query (for example inserting into non existing table).
Here is an example of how to throw an exception in mysql, which works on versions 5.5 and above:
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Custom error';
Details can be found here: https://dev.mysql.com/doc/refman/5.5/en/signal.html