Yes, use a handler for this:
http://dev.mysql.com/doc/mysql/en/declare-handlers.html
create trigger tgr
after insert on mytable
for each row
begin
declare continue handler
for SQLSTATE '23000'
call p_handle_duplicate();
/*
You original trigger code goes here
*/
end;
The call to p_handle_duplicate(); is just a placeholder for your handler. You can put any statement there. For a sequence of statement, use a begin..end block that contains the actual handler code.
For a complete list of existing error conditions, see
http://dev.mysql.com/doc/mysql/en/error-handling.html
Now, SQLSTATE 23000 is a bit arcane, and if you are going to use that again, its better to declare a condition:
create trigger tgr
after insert on mytable
for each row
begin
declare DUPLICATE_ROW condition for SQLSTATE '23000'
declare continue handler
for DUPLICATE_ROW
call p_handle_duplicate();
/*
You original trigger code goes here
*/
end;
More info on condition declarations:
http://dev.mysql.com/doc/mysql/en/declare-conditions.html
Good luck!