javaexception exception是所有异常的
exception是所有异常的父类,在 java.lang包里面
Exception java.lang中
~~~~~~~~~~
java中的异常多了,但是常见的异常也就如下几种:
import java.nio.*;
import java.util.*;
class testexception {
public static void main(string[] args) {
testexception t=new testexception();
t.testindexoutofboundsexception();
}
// 1。arithmeticexception异常。 被除数为0时触发
public void testarithmeticexception() {
int a=10;
int b=0;
int c=a/b;
}
// 2。arraystoreexception异常。 数组类型不正确时触发
public void testarraystoreexception() {
object x[]=new string[3];
x[0]=new integer(0);
}
// 3。bufferoverflowexception异常。
public void testbufferoverflowexception() {
int cap=10;
bytebuffer bf=bytebuffer.allocate(cap);
system.out.println(bf);
for(int i=0;i bf.put((byte)i); } system.out.println(bf); // cause exception bf.put((byte)10); } // 4。bufferunderflowexception异常。 public void testbufferunderflowexception() { int cap=10; bytebuffer bf=bytebuffer.allocate(cap); system.out.println(bf); for(int i=0;i bf.put((byte)i); } system.out.println(bf); // cause exception bf.get(); } // 5。classcastexception异常。 类的类型不正确的cast的时候触发。 public void testclasscastexception() { object x=new integer(0); system.out.println((string)x); } // 6。emptystackexception异常。 堆栈为空的时候触发 public void testemptystackexception() { stack t=new stack(); t.push (new object()); t.pop(); // cause exception t.pop(); } // 7。illegalargumentexception异常。 调用方法时传入不合法的参数的时候触发。 public void testillegalargumentexception() { thread.currentthread().setpriority(thread.min_priority); // caush exception thread.currentthread().setpriority(99); } // 8。indexoutofboundsexception异常。 索引超出边界时触发。 public void testindexoutofboundsexception() { list l=new arraylist(); l.add("t"); l.add("a"); l.add("n"); l.add("k"); l.add("s"); collections.swap(l,0,9); } // 9。arrayindexoutofboundsexception异常。 索引超出数组边界时触发。 public void testarrayindexoutofboundsexception() { list v=new arraylist(); v.add(new object()); v.get(0); // cause exception v.get(-1); } // 10。stringindexoutofboundsexception异常。 索引超出字符串边界时触发。 public void teststringindexoutofboundsexception() { string s="hello"; s.charat(-1); } }
package java.lang
相关阅读
甜蜜的人生吻戏 成为众人瞩目的焦点
牛奶敷脸美白吗 用少许酸奶对水
画家波洛克 黑等多种颜色
空调的构造 空调器制冷降温
dnf帝国套 现在TX还没明确说明
2013安徽公务员职位表 2013年4月13日
cf怎么加入绿色联盟 玩家加入绿色联盟后
红色彗星 比黄蜂有过之而无不及
cf怎么点亮 只要你有内测资格
肤速宁 纯天然植物提取液外用
asp木马 你想做asp木马是吗
美与丑的世界 被生动地描绘出来
流星蝴蝶剑密集 你的游戏版本问题
股票600392 5弱势下行了
田忌赛马数学题 当田忌的马随机出阵时
芙蓉姐姐是谁 ——同小说中的生日吻合
狐狸雨韩文歌词 回忆爱过的时光的同时
红字发票 重新开具销售发票
泡的拼音 萝卜等放在加了盐
深圳至上海机票 都是2折的多
类似美国派的电影 MaleGigolo
花信歌词 刻在红叶上的
老人头标志 因为杂牌的质量
索爱w610c 机身颜色黑色挑错
玛雅wang发信到 南昌象湖公园
苹果4可以升级ios7吗 否则会出现卡顿问题
美国青春偶像电影 推荐楼主上58看
淘宝特卖和淘宝网有什么区别 这个是属于第三方的
美菱冰箱好吗 制冷效果不错
火狐浏览器好用吗 推荐遨游和世纪之窗
男朋友结婚了新娘却不是我 没有我要钱干什么
美宜佳便利店利润 联系好固定的供货源
猫游记boss 60恶灵之王60以上
09电影 《特种部队》导演
2010世锦赛美国男篮 球员位置现役球队
脑残星 故而称为“脑残者的游戏”
苏子美和苏轼 以及向下转发公文
agp插槽 AGP的一般比较短
花开不败 页数232页
河北电视台主持人 已经是比较成熟的状态