try { // some operation causing an exception } catch (SqlException e) { if (e.ErrorCode == 0x80131904) // ... return null; throw; }