易截截图软件、单文件、免安装、纯绿色、仅160KB

JAVA异常总结 继承

以下是对JAVA异常的继承机制的一些总结。
1. RuntimeException与Exception, Error不同点: 当方法体中抛出非RuntimeException(及其子类)时,方法名必须声明抛出的异常;但是当方法体中抛出RuntimeException(包括RuntimeException子类)时,方法名不必声明该可能被抛出的异常,即使声明了,JAVA程序在某个调用的地方,也不需要try-catch从句来处理异常。
class TestA{
//compiles fine.we don't need to claim the RuntimeException to be thrown here
void method(){
throw new RuntimeException();
}
}
class TestB{
void method() throws RuntimeException{
throw new RuntimeException();
}

void invokeMethod(){
//compiles fine. we don't need the try-catch clause here
method();
}
}
class TestC{

//compiles error.we need to claim the Exception to be thrown on the method name
void method(){
throw new Exception();
}
}
class TestD{
//compiles fine.
void method() throws Exception{
throw new Exception();
}
}
以下所有的相关异常的特性都不包括RuntimeException及其子类。
2. 假如一个方法在父类中没有声明抛出异常,那么,子类覆盖该方法的时候,不能声明异常。
class TestA{
void method(){}
}
class TestB extends TestA{

//complies error if the method overrided pertaining to the base class doesn't declare throwing exceptions
void method() throws Exception{
throw new Exception();
}
}
 
3. 假如一个方法在父类中声明了抛出异常,子类覆盖该方法的时候,要么不声明抛出异常,要么声明被抛出的异常继承自它所覆盖的父类中的方法抛出的异常。
class TestA{
void method() throws RuntimeException{}
}
class TestB extends TestA{
//compiles fine if current method does not throw any exceptions
void method(){}
}
class TestC extends TestA{
//compiles fine because NullPointerException is inherited from RuntimeException which is thrown by the overrided method of the base class
void method() throws NullPointerException{}
}
class TestD extends TestA{
//compiles error because Exception thrown by current method is not inherited from RuntimeException which is thr


相关文档:

java中使用ibatis来调用存储过程(下)

3.3 游标循环最佳策略
我们在进行PL/SQL编程时,经常需要循环读取结果集的数据。进行逐行处理,这个过程就需要对游标进行循环。对游标进行循环的方法有多种,我们在此一一分析。
create or replace procedure proccycle(p varchar2)   
as   
cursor c_postype is select pos_type, description ......

java利用smslib发送短信

java利用smslib发送短信.
自己写一个小程序,我在java1.6.0_10;smslib-v3.4.5下运行成功. 可以我的资源里面下载.
http://hi.csdn.net/link.php?url=http://yangzl0123.download.csdn.net
,主要是以下几个类.
Level_Final_Serial.java:串口底层操作
Serial_For_Smslib.java:对Level_Final_Serial的进一步封装,可以直接发 ......

java 删除文件及目录


java中删除目录事先要删除目录下的文件或子目录。用递归就可以实现。
public void del(String filepath) throws IOException{
File f = new File(filepath);//定义文件路径        
if(f.exists() && f.isDirectory()){//判断是文件还是目录
    if( ......

java中Thread线程中的 start()和run()方法的区别


两种建立线程对象的方法:
    Extends Thread
    implement Runnable
   这两种方法都可以创建一个线程对象,
public class TestThread {
    public static void main(String arg[]){
        newThread thread = new ne ......

JAVA WEB学习笔记(四)-Servlet过滤器

一、Servlet过滤器的概念:
***************************************************************************************
Servlet过滤器是在Java Servlet规范2.3中定义的,它能够对Servlet容器的请求和响应对象进行检查和修改。   
Servlet过滤器本身并不产生请求和响应对象,它只能提供过滤作用。Servlet过期能 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号