Note that there are some explanatory texts on larger screens.

plurals
  1. POExceptions in a thread are written to System.err instead of getting caught
    primarykey
    data
    text
    <p>I've seen it happen a few times already but I can't seem to find any mention for this. In this case I'm doing network operations and upon not resolving a host the worker thread dies and logcat shows the following:</p> <pre><code>Warning System.err 8/14/2011 8:41:58 PM 4355 java.net.UnknownHostException: Unable to resolve host "q": No address associated with hostname Warning System.err 8/14/2011 8:41:58 PM 4355 at java.net.InetAddress.lookupHostByName(InetAddress.java:496) Warning System.err 8/14/2011 8:41:58 PM 4355 at java.net.InetAddress.getAllByNameImpl(InetAddress.java:277) Warning System.err 8/14/2011 8:41:58 PM 4355 at java.net.InetAddress.getAllByName(InetAddress.java:249) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) Warning System.err 8/14/2011 8:41:58 PM 4355 at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) ... Warning dalvikvm 8/14/2011 8:41:58 PM 4355 threadid=10: thread exiting with uncaught exception (group=0x4013a760) </code></pre> <p>As you see the exception is written to the System.err stream (which is Java's stderr that Android doesn't actually use or supports). It's not caught by anything:</p> <ol> <li>try catch statements don't work since this is in a thread opened by the line try expected.</li> <li><code>Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler())</code> doesn't work too, which just seems very wrong.</li> </ol> <p>So my questions are:</p> <ol> <li>Why do some exceptions behave differently than others on a <em>system</em> level (aka they bypass <code>Thread.setDefault</code>)?</li> <li>How do I still get these exceptions without resorting to reading System.err or other "hacky" solutions?</li> </ol> <p>Edit: Android 3.1, Samsung Tab 10.1, but I'm pretty sure this isn't a device or OS dependent issue.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload