Re: can't throw
On Wednesday, September 12, 2012 1:32:01 AM UTC-5, Robert Klemme wrote:
On 11.09.2012 22:16, bob smith wrote:
Am I the only one who wanted to throw an Exception but couldn't
because I was overriding a method that threw nothing?
In particular, I'm subclassing Thread and can't throw an Exception in
the run method. I suspect this is a more general issue though.
Why are you subclassing Thread in the first place?
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
There are two ways to create a new thread of execution. One is to declare a=
class to be a subclass of Thread. This subclass should override the run me=
thod 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 v=
alue could be written as follows:
class PrimeThread extends Thread {
long minPrime;
PrimeThread(long minPrime) {
this.minPrime = minPrime;
}
public void run() {
// compute primes larger than minPrime
. . .
}
}
The following code would then create a thread and start it running:
PrimeThread p = new PrimeThread(143);
p.start();