Java SE 异常
package demo;
class TestA{
public int devide(int x,int y) throws ArithmeticException , DevideByMinusException{
if(y<0)
throw new DevideByMinusException("被除数为负",y);
int result=x/y;
return result;
}
}
public class TestException {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try{
// int result=new TestA().devide(3,0);
int result=new TestA().devide(3,-1);
System.out.println(result);
}catch(ArithmeticException e){
System.out.println("in >>ArithmeticException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}catch(DevideByMinusException e){
System.out.println("in >>DevideByMinusException<< ");
System.out.println(e.getMessage());
// e.printStackTrace();
}
System.out.println("program is running here,that is normal!");
}
}
class DevideByMinusException extends Exception{
int devisor;
public DevideByMinusException(String msg,int devisor){
super(msg);
this.devisor=devisor;
}
public int getDevisor(){
return devisor;
}
}
相关文档:
一、从根本上认识java.lang.String类和String池
首先,我建议先看看String类的源码实现,这是从本质上认识String类的根本出发点。从中可以看到:
1、String类是final的,不可被继承。public final class String。
2、String类是的本质是字符数组char[], 并且其值不可改变。private final char value[];
然后打开Str ......
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class cls = com.lwf.util.CommonUtil.class;
Object obj = cls.newInstance();
Method addMethod = cls.ge ......
要理类加载体系结构,就必须清楚如下几点比较基本的原则:
1. classLoader是一种父子树形结构(注:这里不是指类继承的父子关系)
2. 父classLoader无法看到子classLoader加载的类
3、虚拟机遵守双亲委托加载原则,即任何子classLoader须首先委托父classLoader先加载需要的类,当父classLoader加载不到时再由子classLoa ......
Reflection 的简单应用,包括field, method,constructor的应用。
package com.gaoqian.reflection;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Typ ......
package demo;
interface Runner{
int ID=1;
void run();
void fly();
}
abstract class AI implements Runner{
public void run(){
System.out.println("I am running");
}
public void bb(int x,int y){
System.out.println((x+y));
}
& ......