亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

JAVA認(rèn)證

java運(yùn)行常見(jiàn)異常舉例

時(shí)間:2024-08-14 01:43:27 JAVA認(rèn)證 我要投稿
  • 相關(guān)推薦

java運(yùn)行常見(jiàn)異常舉例

  下面小編為大家總結(jié)了幾個(gè)JAVA中常見(jiàn)的RuntimeException,希望對(duì)你們有所幫助:

  NullPointerException:空指針異常類(lèi)

  示例1:

  package com.darkmi.basic;

  public class Test {

  public static void main(String[] args) {

  System.out.println(toUpper(null));

  }

  public static String toUpper(String str){

  return str.toUpperCase();

  }

  }

  異常信息如下:Exception in thread “main” java.lang.NullPointerException

  at com.darkmi.basic.Test.toUpper(Test.java:11)

  at com.darkmi.basic.Test.main(Test.java:6)

  ArrayIndexOutOfBoundsException:數(shù)組下標(biāo)越界異常

  示例2:

  package com.darkmi.basic;

  public class Test {

  public static void main(String[] args) {

  int[] a = {0,1,2,3};

  System.out.println(a[4]);

  }

  }

  異常信息如下:

  Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4

  at com.darkmi.basic.Test.main(Test.java:7)

  ArithmeticExecption:算術(shù)異常類(lèi):

  示例3:

  package com.darkmi.basic;

  public class Test {

  public static void main(String[] args) {

  int a = 10 / 0;

  System.out.println(a);

  }

  }

  異常信息如下:

  Exception in thread “main” java.lang.ArithmeticException: / by zero

  at com.darkmi.basic.Test.main(Test.java:6)

  ClassCastException:類(lèi)型強(qiáng)制轉(zhuǎn)換異常

  示例4:

  package com.darkmi.basic;

  public class Test {

  public static void main(String[] args) {

  testParse(“aaa”);

  }

  public static void testParse(Object str){

  Integer i = (Integer)str;

  }

  }

  異常信息如下:

  Exception in thread “main” java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

  at com.darkmi.basic.Test.testParse(Test.java:10)

  at com.darkmi.basic.Test.main(Test.java:6)

【java運(yùn)行常見(jiàn)異常舉例】相關(guān)文章:

java運(yùn)行常見(jiàn)異常類(lèi)型07-11

汽車(chē)不必維修的10個(gè)常見(jiàn)異常07-16

Java中最常見(jiàn)的錯(cuò)誤盤(pán)點(diǎn)05-28

Java編寫(xiě)計(jì)算器的的常見(jiàn)做法07-08

航運(yùn)行業(yè)常見(jiàn)船務(wù)公司簡(jiǎn)稱(chēng)與縮寫(xiě)09-12

sun認(rèn)證Java枚舉常見(jiàn)7種用法08-13

2017年java常見(jiàn)面試題及答案08-22

JAVA常見(jiàn)編碼問(wèn)題解決方法10-24

ORACLE下開(kāi)發(fā)JAVA程序常見(jiàn)問(wèn)題解答09-30

Java與Java web的區(qū)別08-22