Community
Participate
Working Groups
Created attachment 191907 [details] Insert "throw" keyword By accident I stumbled across this line in AbstractChannel.setServiceProxy(): if (!notifying_channel_opened) new Error("setServiceProxe() can be called only from channel open call-back"); which is obviously missing the "throw" keyword. Attached patch fixes this.
This is intentional. From Java language specs: 11.2.1 Why Errors are Not Checked Those unchecked exception classes which are the error classes (Error and its subclasses) are exempted from compile-time checking because they can occur at many points in the program and recovery from them is difficult or impossible. A Java program declaring such exceptions would be cluttered, pointlessly. And I like this particular exception to be Error - to make recovery difficult or impossible. The intend is to kill a client immediately if it does not honor API contract.
I think there is a misunderstanding. I don't suggest to add a throws clause to the method declaration. Sorry if I was not clear. The issue is that the line if (!notifying_channel_opened) new Error(...); is obsolete without "throw" before "new", i.e. it should be if (!notifying_channel_opened) throw new Error(...); That's all.
Of course, you are absolutely right. My fault - I misunderstood you. Committed the patch. Thanks!