locked
What does this statement mean? RRS feed

  • Question

  • Thank you so much. I appreciate that.
    By the way - one more questoin -
    What this do???
    catch (Exception ex)
                {
                   return false;
                }

    Thank You
    • Split by David M Morton Monday, August 31, 2009 8:52 PM Another question
    Monday, August 31, 2009 8:41 PM

Answers

  • I split this question out, because it's separate from your first.  Please keep your questions to one question per post.

    It means that any exceptions (errors) that happen within the "try" block will be "caught", that is, they won't crash the whole application.  Instead of crashing the application, the method returns false instead of true.  The general layout is this:

    public bool SomethingDangerous()
    {
        try
        {
            // do something dangerous
        } 
        catch (Exception ex)
        {
            // an error occurred (was "thrown") and the instructions being executed move to here. 
            return false;

            // from here, you can also use the C# "throw" keyword which will cause the exception to be truly "thrown".
        }
        return true;
    }

    See this link for more information.

    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
    • Proposed as answer by Rahul P Nath Tuesday, September 1, 2009 4:20 AM
    • Marked as answer by Figo Fei Wednesday, September 2, 2009 7:25 AM
    Monday, August 31, 2009 8:56 PM