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();
}
}
Similar Java Tutorials
- Odd Even in Java
- Method to print exception information in Java
- Exception Handling by Using try-catch in Java
- Checked Exception vs Unchecked Exception
- Exception Hierarchy in Java
- Java Exception Handling Interview Questions
- final finally finalize in java
- User Defined Exception in Java
- Exception Handling Keyword in Java
- throw throws in Java
- try with multiple catch block in Java