When you raise the error you can provide a MessageId instead of a Message text. This number will be found in the Number
propertie of the Exception:
SQL:
RAISERROR(50001, 12, 1)
C#:
if (sqlException.Number == 50001)
{
throw new CustomSQLException(//whatever);
}