Raise Error in C# (.NET) / Throw Error/Exception in C# (.NET)
The following code generates an exception if the supplied text (password) is less than eight characters.
try { if (sPassword.Length < 8 ) { throw new Exception("Password should contain mimimum 8 chars"); } } catch(Exception ex1) { sMessage= ex1.Message.ToString(); return false; }
This way of raising user-defined exception helps in efficient way of handling exceptions
No comments:
Post a Comment