From DBI:
ShowErrorStatement
Type: boolean, inherited
The ShowErrorStatement attribute can be used to cause the relevant Statement text to be appended to the error messages generated by the RaiseError, PrintError, and PrintWarn attributes. Only applies to errors on statement handles plus the prepare(), do(), and the various select*() database handle methods. (The exact format of the appended text is subject to change.)
If $h->{ParamValues} returns a hash reference of parameter (placeholder) values then those are formatted and appended to the end of the Statement text in the error message.
So instead of
RaiseError and/or
PrintError you need to work with
ShowErrorStatement. That might remove the need to use the
eval approach below if that is not appealing.
You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.