Windows Phone Developers

Monday, April 12, 2010

How to Raise Exceptions in C# / .NET

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 Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment