I think a case could also be made for logging the UnknownHostException without the stack trace (just the server name) as an in between step. Thanks for the bugreport.
On Fri, Jan 25, 2013 at 3:08 PM, Boris Burtin <[email protected]> wrote: > Thanks for responding. I can see the reasoning. Just seems weird that > the behavior isn't documented, and that there's no way for me to override > it. I'll file a bug for updating the Javadoc. > > > On Friday, January 25, 2013 2:40:10 PM UTC-8, Robert Greenwalt wrote: > >> You can always do the dns lookup yourself and log an error if it's >> invalid. The DNS cache will ensure it's not wasted effort. >> >> >> On Fri, Jan 25, 2013 at 2:39 PM, Robert Greenwalt <[email protected]>wrote: >> >>> I think the log was getting quite full of these exceptions (mobile >>> devices often don't have a network and apps aren't so good at checking that >>> first) so we stopped logging them. If you look at the blame for this code >>> you can see the reasoning. >>> >>> >>> >>> On Fri, Jan 25, 2013 at 2:31 PM, Boris Burtin <[email protected]> wrote: >>> >>>> I was racking my brain, trying to figure out why one of my users was >>>> having trouble connecting and nothing was in the logs. Finally I looked at >>>> the Android source and realized that the logging code explicitly ignores >>>> UnknownHostException. Even worse, the Javadoc doesn't specify this >>>> behavior. >>>> >>>> Does this sound like a bug to anyone, as opposed to a feature? In my >>>> case, the user enters the hostname, so it's possible to get this exception >>>> while the user has a network connection. >>>> >>>> /** >>>> * Handy function to get a loggable stack trace from a Throwable >>>> * @param tr An exception to log >>>> */ >>>> public static String getStackTraceString(Throwable tr) { >>>> if (tr == null) { >>>> return ""; >>>> } >>>> >>>> // This is to reduce the amount of log spew that apps do in the >>>> non-error >>>> // condition of the network being unavailable. >>>> Throwable t = tr; >>>> while (t != null) { >>>> if (t instanceof UnknownHostException) { >>>> return ""; >>>> } >>>> t = t.getCause(); >>>> } >>>> >>>> StringWriter sw = new StringWriter(); >>>> PrintWriter pw = new PrintWriter(sw); >>>> tr.printStackTrace(pw); >>>> return sw.toString(); >>>> } >>>> >>>> >>>> -- >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to android-d...@**googlegroups.com >>>> >>>> To unsubscribe from this group, send email to >>>> android-developers+**[email protected] >>>> For more options, visit this group at >>>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en> >>>> >>>> >>>> >>> >>> >> -- > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

