innodb retry on ERROR 1213 (40001): Deadlock found

innodb retry on ERROR 1213 (40001): Deadlock found

Hi,
I recently had to switch some tables from MyIsam to InnoDB, and now I am getting errors when doing inserts from different threads:

ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

I am currently changing my code by catching this mysql errorcode and retrying the insert again (and again if necessary).
I was wondering if there is a way without having to add these retries to my source code?
For example: is there a "retry" option in TMyQuery or something similar?

Thanks!