Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!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: Wed, 12 Sep 2012 23:24:29 +0200 Lines: 48 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 lsCwpvyP0FmDOYLOJARcxgMyRv96Wn7mgrCi+eofHLj9WyoiU8qMI5oip27npzDpI= Cancel-Lock: sha1:T6ZZPkJQ7aglCrdKTrf+KnHhJ/I= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <2da52903-55b6-4288-8f95-9799a5ce874c@googlegroups.com> Xref: csiph.com comp.lang.java.programmer:18696 On 12.09.2012 21:52, Lew wrote: > bob smith wrote: >> Robert Klemme wrote: >>> Why are you subclassing Thread in the first place? >> >> There are two ways to create a new thread of execution. One is to declare a class to be a subclass of I find the wording of this answer unfortunate: you create a thread of execution by invoking Thread.start(). Bob, what you probably meant was there are two ways to create functionality executed in a separate thread. But then Lew's comment applies: > There are far more than two ways. > >> Thread. This subclass should override the run method of class Thread. An instance of the subclass >> can then be allocated and started. For example, a thread that computes primes larger than a stated >> value could be written as follows: > You explained what you're doing, but you didn't answer Robert's question of why. Exactly. Again: why are you doing this, Bob? > Why are you subclassing Thread in the first place? Most people's answers in this thread revolve around the fact how a method without declared checked exceptions can be made to throw exceptions anyway. But: 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. Instead, you should be handling exceptions in run() and terminate the thread gracefully (i.e. by returning from run()). > It's abnormal and you aren't doing anything that obviously calls for this idiom. > > "Because I can!" only answers a certain question asked of a male dog. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/