Demo of IllegalArgumentException | java.lang package



Example of IllegalArgumentException present in java.lang package
Figure1

Class Hierarchy:


IllegalArgumentException is a class present in java.lang.* package and has following class hierarchy.


Class hierarchy of IllegalArgumentException present in java.lang package
Figure2


Description: 


Thrown to indicate that a method has been passed an illegal or inappropriate argument.



Since:


JDK1.0


Example:


package com.javamultiplex.java.lang.exceptions;
/**
* @author Rohit Agarwal
* @version 1.0
* @category java.lang/Exception
* @since JDK 1.0
*/
class MyThread implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
public class IllegalArgumentExceptionDemo {
public static void main(String[] args) {
MyThread thread = new MyThread();
Thread th = new Thread(thread);
/*
* IllegalArgumentException will be thrown because Thread priority can
* be 1 to 10.
*
* Thread.MIN_PRIORITY is equivalent to 1 Thread.MAX_PRIORITY is
* equivalent to 10 Thread.NORM_PRIORITY is equivalent to 5
*/
th.setPriority(11);
th.start();
}
}

Output:


Output of IllegalArgumentException
Figure3

References:



Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.

About Author:

I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.


Let's Get Connected: Linkedin | Facebook |

Demo of IllegalArgumentException | java.lang package Demo of IllegalArgumentException | java.lang package Reviewed by Rohit Agarwal on 10/25/2017 Rating: 5

No comments:

Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.

Powered by Blogger.