Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: can't throw Date: Thu, 13 Sep 2012 23:32:20 +0200 Lines: 36 Message-ID: References: <19af6b94-7a1e-4491-afb2-79782406f560@googlegroups.com> <2da52903-55b6-4288-8f95-9799a5ce874c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net QOI2BqKhfQl7D02srOpuJw3aTfROSPAgy/qTzlbil3ZXHkNpeivxJutFOWGFmG3Ig= Cancel-Lock: sha1:PSnw8QiYyV2neZr1lFt0Co96uhg= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:18749 On 09/13/2012 12:10 AM, Daniel Pitts wrote: > On 9/12/12 2:24 PM, Robert Klemme wrote: >> there is no point in throwing from Thread.run() >> or Runnable.run() other than catastrophic failures (all Errors such as >> OOM, all RuntimeExceptions which are really programmer mistakes) because >> you cannot customize handling of exceptions thrown from the run() >> method: this method is only invoked from class Thread and probably >> others in the Java standard library itself. > Actually, you can handle exceptions from a Thread. There is the > UncaughtExceptionHandler: > > > > Though the only valuable use I have ever seen from this is in logging > those failures differently than the default output. Right, I completely forgot about that. The issue with this is that you have far less context than inside method run(). So handling there is certainly preferred. >> Instead, you should be >> handling exceptions in run() and terminate the thread gracefully (i.e. >> by returning from run()). > > Agreed. If you need some other code to propagate an Exception, you need > to pass that information along. Exceptions are meant to unwind the > stack. For most practical purposes a Thread's run() method really has no > stack to unwind. Even if you could throw an Exception from it, where > would that Exception go? Who's going to deal with it? ... other than the default uncaught exception handler. Exactly. Kind regards robert