Technically, you could System.exit(int) (the int value would be the value returned from the process, and probably nonzero to indicate an error). However, this is a little cruel.
You can also interrupt yourself.
Thread.currentThread().interrupt();
But:
- this is still an exception. You are not throwing it explicitly, but still the result of
InterruptedException - your thread must do some I / O in the future to register this interrupt. If it is exclusively computational, then because of this it will not work.
eg. (pay attention to sleep() to catch the interrupt):
public class Test { public static void method() throws Exception { Thread.currentThread().interrupt(); Thread.sleep(100); System.out.println("method done"); } public static void main(String[] args) throws Exception { method(); System.out.println("done"); } }
gives me:
Exception in thread "main" java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at T.method(T.java:5) at T.main(T.java:9)
source share