What to return from a function if an exception is thrown?
Posted on 2006-05-25
I have a function that I call to create an arrayList of objects. I've enclosed it in a 'Try...Catch' block. I return the arrayList at the end of the 'Try' and in the 'Catch' I display a messagebox with whatever the exception is in it's message.
I'm getting a warning that 'Function blah doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.'
So, I'm just wondering what I'm supposed to do to get rid of this warning? Do I return an empty arrayList and then test for that in the function call? Or is there a better solution?