BDE Key Violation error

In my database exception handling, I find that adding a record with a
duplicate primary key generates BDE error 9729 (Key Violation). This is the
same erorr you get when trying to delete a record that is linked to other
tables by foreign keys. I have checked the category and subcode of the error
and they are identical for both error conditions. How can I distinguish
which of these two errors has occurred so I can relay my own message? I
would rather not check message text.

Wayne