首页 > 编程知识 正文

IllegalArgumentException异常,lang.illegalargumentexception

时间:2023-05-03 08:08:12 阅读:209877 作者:4366

IllegalArgumentException:非法参数异常

抛出的异常表明向方法传递了一个不合法或不正确的参数。

代码演示

public class ThreadPriorityDemo { public static void main(String[] args) { ThreadPriority tp1 = new ThreadPriority(); ThreadPriority tp2 = new ThreadPriority(); ThreadPriority tp3 = new ThreadPriority(); tp1.setName("奥拉夫"); tp2.setName("挖掘机"); tp3.setName("德邦总管"); //获取默认优先级 //System.out.println(tp1.getPriority());//5 //System.out.println(tp2.getPriority());//5 //System.out.println(tp3.getPriority());//5 //设置优先值 //IllegalArgumentException:非法参数异常 tp1.setPriority(1000); //通过查看API设置正确的优先级 // tp1.setPriority(1); // tp3.setPriority(10); //启动线程 // tp1.start(); // tp2.start(); // tp3.start(); }}

结果:

Exception in thread "main" java.lang.IllegalArgumentExceptionat java.base/java.lang.Thread.setPriority(Thread.java:1188)at com.ginger.demo03.ThreadPriorityDemo.main(ThreadPriorityDemo.java:21)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。