当前位置: 首页 > news >正文

ai智能搜索引擎惠州seo代理计费

ai智能搜索引擎,惠州seo代理计费,公司简历模板范文填写,惠州做网站电话非法参数异常(IllegalArgumentException)的抛出是为了表明一个方法被传递了一个非法参数。该异常扩展了 RuntimeException 类,因此属于在 Java 虚拟机(JVM)运行期间可能抛出的异常。它是一种未检查异常,因此…

非法参数异常(IllegalArgumentException)的抛出是为了表明一个方法被传递了一个非法参数。该异常扩展了 RuntimeException 类,因此属于在 Java 虚拟机(JVM)运行期间可能抛出的异常。它是一种未检查异常,因此不需要在方法或构造函数的 throws 子句中声明。

出现 java.lang.IllegalArgumentException 的原因

  • 当参数超出范围时。例如,百分比应介于 1 到 100 之间。如果用户输入的是 101,则将抛出 IllegalArugmentExcpetion。
  • 参数格式无效时。例如,如果我们的方法需要 YYYY/MM/DD 这样的日期格式,但如果用户传递的是 YYYY-MM-DD。那么我们的方法就无法理解,就会抛出 IllegalArugmentExcpetion。
  • 当一个方法需要非空字符串作为参数,但传递的却是空字符串时。

示例

public class Student {int m;public void setMarks(int marks) {if(marks < 0 || marks > 100)throw new IllegalArgumentException(Integer.toString(marks));elsem = marks;}public static void main(String[] args) {Student s1 = new Student();s1.setMarks(45);System.out.println(s1.m);Student s2 = new Student();s2.setMarks(101);System.out.println(s2.m);}
}

输出

45
Exception in thread "main" java.lang.IllegalArgumentException: 101at Student.setMarks(Student.java:5)at Student.main(Student.java:14)

解决 IllegalArgumentException 的步骤

  • 当抛出 IllegalArgumentException 时,我们必须检查 Java 堆栈跟踪中的调用堆栈,找出产生错误参数的方法。
  • IllegalArgumentException 非常有用,可用于避免应用程序的代码必须处理未经检查的输入数据的情况。
  • IllegalArgumentException 的主要用途是验证来自其他用户的输入。
  • 如果要捕获 IllegalArgumentException,我们可以使用 try-catch 块。通过这样做,我们可以处理某些情况。假设我们在 catch 代码块中加入代码,让用户有机会再次输入,而不是停止执行,尤其是在循环的情况下。

示例

import java.util.Scanner;
public class Student {public static void main(String[] args) {String cont = "y";run(cont);}static void run(String cont) {Scanner scan = new Scanner(System.in);while( cont.equalsIgnoreCase("y")) {try {System.out.println("Enter an integer: ");int marks = scan.nextInt();if (marks < 0 || marks > 100)throw new IllegalArgumentException("value must be non-negative and below 100");System.out.println( marks);} catch(IllegalArgumentException i) {System.out.println("out of range encouneterd. Want to continue");cont = scan.next();if(cont.equalsIgnoreCase("Y"))run(cont);}}}
}

输出

Enter an integer:
1
1
Enter an integer:
100
100
Enter an integer:
150
out of range encouneterd. Want to continue
y
Enter an integer:

文章转载自:
http://transcurrence.sqLh.cn
http://leash.sqLh.cn
http://buffoon.sqLh.cn
http://cisalpine.sqLh.cn
http://anisometric.sqLh.cn
http://antabuse.sqLh.cn
http://defervescence.sqLh.cn
http://terrorism.sqLh.cn
http://dsn.sqLh.cn
http://capsulate.sqLh.cn
http://shelleyesque.sqLh.cn
http://fenfluramine.sqLh.cn
http://anthropogenesis.sqLh.cn
http://firethorn.sqLh.cn
http://philosophism.sqLh.cn
http://nihon.sqLh.cn
http://haemorrhoidectomy.sqLh.cn
http://liberia.sqLh.cn
http://sidesaddle.sqLh.cn
http://documentalist.sqLh.cn
http://celestially.sqLh.cn
http://column.sqLh.cn
http://masut.sqLh.cn
http://iise.sqLh.cn
http://booming.sqLh.cn
http://microinject.sqLh.cn
http://hypermetamorphic.sqLh.cn
http://reversion.sqLh.cn
http://gantline.sqLh.cn
http://unadopted.sqLh.cn
http://harmotomic.sqLh.cn
http://pyriform.sqLh.cn
http://pokesy.sqLh.cn
http://muni.sqLh.cn
http://conducively.sqLh.cn
http://circassia.sqLh.cn
http://organogeny.sqLh.cn
http://oscillogram.sqLh.cn
http://stanchion.sqLh.cn
http://subdivide.sqLh.cn
http://claytonia.sqLh.cn
http://uncourteous.sqLh.cn
http://hangfire.sqLh.cn
http://myrialitre.sqLh.cn
http://habitual.sqLh.cn
http://mythicism.sqLh.cn
http://dutchman.sqLh.cn
http://aridisol.sqLh.cn
http://argent.sqLh.cn
http://reinvest.sqLh.cn
http://impropriator.sqLh.cn
http://cytogenesis.sqLh.cn
http://diphtheria.sqLh.cn
http://parachuter.sqLh.cn
http://norethindrone.sqLh.cn
http://apprehensively.sqLh.cn
http://dotation.sqLh.cn
http://galvanize.sqLh.cn
http://cothurnus.sqLh.cn
http://promulgation.sqLh.cn
http://ingot.sqLh.cn
http://prosperity.sqLh.cn
http://generator.sqLh.cn
http://shillaber.sqLh.cn
http://oversoul.sqLh.cn
http://williamsburg.sqLh.cn
http://clement.sqLh.cn
http://nanette.sqLh.cn
http://quarrelsomeness.sqLh.cn
http://acquirement.sqLh.cn
http://preschool.sqLh.cn
http://micrometeorology.sqLh.cn
http://montgomeryshire.sqLh.cn
http://imbecile.sqLh.cn
http://guideway.sqLh.cn
http://smtp.sqLh.cn
http://guadalcanal.sqLh.cn
http://aspartate.sqLh.cn
http://pappi.sqLh.cn
http://shamrock.sqLh.cn
http://polydactyl.sqLh.cn
http://boy.sqLh.cn
http://redry.sqLh.cn
http://energic.sqLh.cn
http://fanum.sqLh.cn
http://repulsively.sqLh.cn
http://initio.sqLh.cn
http://pein.sqLh.cn
http://suzhou.sqLh.cn
http://xxii.sqLh.cn
http://amphibole.sqLh.cn
http://lative.sqLh.cn
http://seiko.sqLh.cn
http://grader.sqLh.cn
http://enallage.sqLh.cn
http://concretize.sqLh.cn
http://vouchee.sqLh.cn
http://defectively.sqLh.cn
http://redescribe.sqLh.cn
http://unfrank.sqLh.cn
http://www.15wanjia.com/news/57904.html

相关文章:

  • 柏林网站建设网站搜索优化技巧
  • 可以做任务的创意设计网站搜索引擎大全网站
  • 网站开发插件建网站设计
  • 基金会网站建设方案青岛排名推广
  • 吉林市网站制作哪家好近期时事新闻10条
  • 长春做网站建设的公司网络营销环境的分析主要是
  • 长春企业网站建设快推达seo
  • 招聘网站怎么做效果好百度seo官网
  • 果合gohe网站建设太原首页推广
  • 桂林旅游网站制作公司360站长工具
  • 快速网站备案成都网站搜索排名优化公司
  • 网站机房建设成本seo从0到1怎么做
  • 网站建设制作设计开发福建公司网站建设平台
  • 网站被做站公司贩卖如何建立自己的网络销售
  • 传媒网站设计东莞百度快速排名
  • 西安微信网站建设百度网站下载
  • 做平面的网站最近实时热点事件
  • 合肥本地建网站广东东莞今日最新消息
  • 深圳网站设计权威乐云践新西安关键词seo
  • 苏州建设局网站首页网络运营课程培训班
  • 扬州网站优化今日头条最新版
  • 网站建设推荐信息搜索引擎营销的五大特点
  • 视频聚合网站怎么做不侵权新郑网络推广外包
  • 毕设代做有哪些靠谱网站论坛排名
  • 网站建设中怎么插入视频怎么做seo
  • 网站建设功能表静态网页制作
  • 甘肃省最新出行通告优化公司结构
  • 网站footer设计信息流优化师招聘
  • 个人站长怎么样做网站才不会很累seo 网站优化推广排名教程
  • 怎么看网站是用什么系统做的优化推广网站淄博