posted 13 years ago
OK, going into a bit more detail - in your last example, if any exception is thrown then xslt will still be null. Which means that when you reach line 16, you're going to get a NullPointerException thrown.
The question you need to ask yourself is: what do I want the method to do in case of error? I reckon there are three plausible options.
1. Return null
2. Return an empty array
3. Throw an exception
Paul's suggestion is to go for option 3. In that case you just throw the exception up to the calling code, and let it decide what to do. This looks sensible to me because the calling code is going to have a better idea about what should be done in the event of error. This utility method doesn't really know enough about the context to know what to do next.
If you want to use 1 or 2, you can do that with a small modification to your code, but you need to allow for the problem I pointed out above.
(By the way - where is the url variable coming from? I'd suggest that should be passed into the method as an argument rather than reliying on a static variable - unless it's a constant).