Question that might show me up (return types!)

This is a discussion on Question that might show me up (return types!) within the C# Programming forums, part of the General Programming Boards category; Firstly hello to everyone, I wanted to ask this question before, but was always ashamed I didn't know the answer. ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    3

    Question that might show me up (return types!)

    Firstly hello to everyone,

    I wanted to ask this question before, but was always ashamed I didn't know the answer.

    This can not be a valid method, can it?

    Code:
    private string getString()
    {
    string thisString;
    return anotherStringMethod(thisString);
    }
    Of course this will compile, but there must be some danger in doing so, I haven't tried placing a try catch around the return statement - would the return invalidate the try and catch?

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Nope, that's perfectly valid. If anotherStringMethod throws an unhandled exception, the stack will continue to unwind until it finds a handler for that exception. If you were concerned about exceptions being thrown from anotherStringMethod, you could put a try-catch in getString to handle them.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    3
    thanks for the info mate,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  3. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM
  4. Class Bank(i have a question)
    By kuwait in forum C++ Programming
    Replies: 3
    Last Post: 05-30-2003, 07:40 AM
  5. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 05:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21