Quote Originally Posted by guyafe View Post
I want the implementer that writes iterate() and any other method that uses getMessage() wont be able to catch this exception and handle it by himself.
Can I do that?
No, I don't think so. If the subclass calls a method that throws an exception, it can catch that exception.

Why don't you do it the traditional way with a private 'finished' boolean member variable in the superclass that you set true from getMessage and check in the while loop in the run method?
Code:
abstract class AbstractAgent implements Runnable {
	private MailBox m_mailbox;
	private boolean finished = false;

	protected final AbstractMessage getMessage() {
		AbstractMessage message = this.m_mailbox.getMessage();
		if (message.getType == KILL_MESSAGE) {
			finished = true;
		}
		else {
			return message;
		}
	}
	
	protected abstract void iterate();
	
	public void run () {
		while(!finished) {
			this.iterate();
		}
	}
}
The unavoidable price of reliability is simplicity...
C.A.R. Hoare