Well, you are already catching the exceptions, right, then adding them to this message (however you may be adding them). Well, use getErrorCode() from the SQLException and determine whether it was that exception that was thrown
before adding the exception to the message.
If you are not using try catch inside the method doing the delete (but rather just throwing the exception and letting a generic routine handle it) then change that method from:
public Whatever whateverYouCallIt(Whatever whatever) throws SQLException {
// whatever
}
to
public Whatever whateverYouCallIt(Whatever whatever) throws SQLException {
try {
// whatever
} catch (SQLException sqle) {
if (sqle.getErrorCode() != whateverTheErrorCodeForTheForeignKeyConstraintIs) {
throw sqle;
}
}
}