class thro
{
public static void main(String args[])
{
try
{
try
{
throw new ArrayIndexOutOfBoundsException("OOB");
}
catch(ArrayIndexOutOfBoundsException f)
{
System.out.println("捕捉内部的Exception");
throw f;
} }catch(ArrayIndexOutOfBoundsException f)
{
System.out.println("再捕捉Exception"+f);
}
}
}
{
public static void main(String args[])
{
try
{
try
{
throw new ArrayIndexOutOfBoundsException("OOB");
}
catch(ArrayIndexOutOfBoundsException f)
{
System.out.println("捕捉内部的Exception");
throw f;
} }catch(ArrayIndexOutOfBoundsException f)
{
System.out.println("再捕捉Exception"+f);
}
}
}
解决方案 »
- 代码求简单优化。。思想也可。谢谢
- 用jtable加载大量数据的一个想法,怎么实现?
- 关于初始化块,静态块,构造函数的先后调用
- 怎样解决运行javaGUI程序后,整个窗体就没有相应的问题
- 有什莫parser可以解析TSV-tab separated 文件吗?
- 我试图想用actionPerformed(ActionEvent e) ,但是很不幸………… 高手请指点迷津
- 怎样配置我的java环境?
- WIN2000 下如何设置环境变量???(急!在线等候)
- 接上一个问题!!(贴出整个程序)再帮忙看看!
- 咨询一个netty channel的问题
- 关于this与同类不同实例互访私有成员权限的两个问题
- 请问下面"这一句话"怎么理解:(关于static,初始化,异常)
楼主【sure2003】截止到2008-07-07 10:43:40的历史汇总数据(不包括此帖):
发帖的总数量:203 发帖的总分数:9217
结贴的总数量:202 结贴的总分数:9187
无满意结贴数:2 无满意结贴分:50
未结的帖子数:1 未结的总分数:30
结贴的百分比:99.51 % 结分的百分比:99.67 %
无满意结贴率:0.99 % 无满意结分率:0.54 %
值得尊敬
{
public static void main(String args[])
{
try
{
try
{
throw new ArrayIndexOutOfBoundsException("OOB"); //直接抛出一个越界的运行时异常
}
catch(ArrayIndexOutOfBoundsException f)//这里捕获越界异常
{
System.out.println("捕捉内部的Exception");//打印异常
throw f;// 这里继续抛出异常
} }catch(ArrayIndexOutOfBoundsException f)//外层再次捕获异常
{
System.out.println("再捕捉Exception"+f);//打印异常
}
}
}
//类名,不符合规范,首字母未大写
class thro
{
//类的主方法,正确
public static void main(String args[])
{
try
{
try
{
// 直接抛出一个越界的运行时异常
throw new ArrayIndexOutOfBoundsException("OOB");
}
// 这里捕获越界异常
catch(ArrayIndexOutOfBoundsException f)
{
// 打印异常
System.out.println("捕捉内部的Exception");
// 这里继续抛出异常
throw f;
}
}
// 外层再次捕获异常
catch(ArrayIndexOutOfBoundsException f)
{
// 打印异常
System.out.println("再捕捉Exception" + f);
}
}
}
public static void main(String args[]) {
try {
try {
// 这里手工抛出了异常
throw new ArrayIndexOutOfBoundsException("OOB");
} catch (ArrayIndexOutOfBoundsException f) {
// 这里捕获了,如果是父类类异常,比如Exception 也能捕获
System.out.println("捕捉内部的Exception");
// 这里你又抛出去了
throw f;
}
} catch (ArrayIndexOutOfBoundsException f) {
// 还是同样的异常,应该换成Exception 看看,呵呵
System.out.println("再捕捉Exception" + f);
}
}
}
//class thro { //类名按规范应该是首字符大写的名词或名词词组(其余单词首字符也要大写) public static void main(String[] args) {
//Java 中提倡将 [] 放数组元素类型后面,能体现出 args 本质上是个对象变量
try {
try {
throw new ArrayIndexOutOfBoundsException("OOB");
//手动创建异常对象并用 throw 语句抛出
} catch (ArrayIndexOutOfBoundsException f) {
//此处 f 的作用域是本 catch 块,不会跟下面的 f 冲突
System.out.println("捕捉内部的Exception");
//捕获到上面抛出的异常并打印出 "捕捉内部的Exception"
throw f;
//再次将捕到的异常上抛 *
}
} catch (ArrayIndexOutOfBoundsException f) {
System.out.println("再捕捉Exception" + f);
//捕获到 * 处抛出的异常并打印出
//"再捕捉Exception" + "java.lang.ArrayIndexOutOfBoundsException: OOB"
//因为异常类 ArrayIndexOutOfBoundsException 的 toString 被设计成返回
//异常类带包名限定的类名加 : 加 new 它时给的异常描述信息 OOB。
}
}}
这个是什么异常.
为什么没有任何提示,会产生这种异常对象...
这是运行时异常,public class ArrayIndexOutOfBoundsException
extends IndexOutOfBoundsException表示用非法数组下标访问数组时抛出的异常信息。如果下标为负或大于等于数组尺寸则为非法下标。
运行时才能发现此异常的。
import java.util.ArrayList;class thro {
public static void main(String args[]) {
ArrayList<String> list=new ArrayList<String>();
System.out.println(list.get(-1));//运行时抛出java.lang.ArrayIndexOutOfBoundsException
}
}