Aaron Fude wrote:
> Hi,
>
> In my personal development efforts, I frequently wrap basic java
> functionality. For example, I have a
>
> String MyIO.urlToString(String url)
>
> or
>
> byte[] MIO.urlToBytes(String url)
>
> etc. These functions catch exceptions and return null if something
> goes wrong. I have other functoins that, for example, load database
> queries into maps.
>
> My gereneral questions are these. Does everybody pretty much end up
> writing convenience wrappers like these for themselves?. If yes, why
> aren't utilities like these commonly available as more or less
> standard libraries? And if no - why not? Is it a bad idea to use these
> and is it for some reason better to, e.g., always form URL's, open
> connections, capture exceptions, etc.
Situations in which I would return null due to an exception are really
rare. More usually, either the exception is a disaster and must be let
flow up the stack to something that can deal with it definitively, or
there is a useful value that can be used, and that should be returned.
In letting exceptions flow up the stack, I do sometimes wrap them in
other exceptions. For example, I might wrap a NumberFormatException in
an InputValidationException, adding data such as a line number and
position in line of the string I tried, and failed, to parse as a number.
Patricia


|