Hi!
I have a noobie problem regarding return statements within methods, and I'd really appreciate any kind of help.
So I have a method containing try and catch block (as required) and much like when you have an if else statement...
... I noted you have to return an object for both the try and catch blocks.
Now in my case my method should return a List object.
The way I have tried to overcome this:
- I've initialised a List object to null as an attribute of the class I'm working in.
- Therefore in the catch block would just simply return the null List object, where as the try block would return the non-empty List (which is what I want).
- I then just
test to see if the List != null, when the method is invoked... and that is that.
However the method always seems to return null (when it shouldn't).
I would really appreciate any suggestions on alternative (and better) ways to overcome this problem.
I hope that all made sense
Thanks in advance.