riccardocagnasso

Handle exception with error code

Jan 3rd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1.             try
  2.             {
  3.                 this.Context.Users.Add(user);
  4.                 this.Context.SaveChanges();
  5.             }
  6.             catch (DbUpdateException ex)
  7.             {
  8.                 var innerException = ex.InnerException.InnerException as SqlException;
  9.                 if (innerException.Number == 2627)
  10.                 {
  11.                     throw new NameAlreadyInUseException(username);
  12.                 }
  13.             }
Advertisement
Add Comment
Please, Sign In to add comment