Foreign keys are there to let SQL ensure that the database never contains "bad" or inconsistent data - it won't let you change information in such a way that a foreign key "points" to a record that no longer exists.
So if you want to delete or change information, you need to delete or change the foreign key row first, then the "target" row.
So if you have an Invoices table, and an InvoiceLines table where each row has a foreign key back to the appropriate Invoice row, then you deleted all the rows from the InvoiceLines table that link to "invoice nnnn" first, then you deleted "invoice nnnn" from the Invoices table.
So first off, all of that should be inside a transaction, so that if you get a failure, you can roll back and not lose half the data and leave the rest.
Second, inside the transaction, use
TRY...CATCH (Transact-SQL) - SQL Server | Microsoft Docs[
^] to detect the problem, and you can use the error information the CATCH supplies to report it how you want before you ROLLBACK the transaction.