IllegalThreadStateException

IllegalThreadStateException is a child class of RunTimeException, Hence it is an unchecked exception. IllegalThreadStateException was explicitly raised by the programmer or API developer to indicate that method is invoked at the wrong time.

For example- We can not restart a thread after starting it, if we try to restart a thread again then we will get the error –

Exception in thread "main" java.lang.IllegalThreadStateException
at java.base/java.lang.Thread.start(Thread.java:793)
at IllegalStateExcep.main(IllegalStateExcep.java:5).

public class IllegalStateExcep {
    public static void main(String[] args) {
        Thread t = new Thread();
        t.start();
        t.start();
    }
}
IllegalThreadStateException

Similar Java Tutorials

Leave a Comment