import java.io.IOException;
class myMath
{
public static int div(int x,int y) throws ArithmeticException,NullPointerException
{
String s=null;
System.out.println(s.equals("aaaa"));
System.out.println("这句话不会执行");
return x/y;
}
}
public class ExceptionDemo
{
public static void main(String[] args)
{
try
{
System.out.println(myMath.div(3,0));
System.out.println("这句话不会执行");
}
catch(NullPointerException npe)
{
}
catch(ArithmeticException ae)
{
ae.printStackTrace();
}
System.out.println("End");
}
}
class myMath
{
public static int div(int x,int y)throws ArithmeticException
{
if(y==0)
{
throw new ArithmeticException("除零异常");
}
return x/y;
}
}
public class ExceptionDemo2
{
public static void main(String[] args)
{
try
{
System.out.println(myMath.div(2,0));
}
catch(ArithmeticException ae)
{
ae.printStackTrace();
System.out.println("haha");
}
System.out.println("haha");
}
}
class Message
{
public boolean build() throws Exception
{
System.out.println("Build");
if(false)
{
throw new Exception();
}
return true;
}
public void send(String message) throws NullPointerException
{
try
{
if(this.build())
{
if(message==null)
{
throw new Exception("消息为空!");
}
System.out.println(message);
}
}
catch(Exception e)
{
}
finally
{
this.close();
}
}
public void close()
{
System.out.println("close");
}
}
public class Main
{
public static void main(String[] args) throws Exception
{
Message msg=new Message();
msg.send(null);
}
}
class explodException extends RuntimeException
{
public explodException(String msg)
{
super(msg);
}
}
class food
{
public void eat(int num)
{
if(num>9999)
{
throw new explodException("Too much");
}
System.out.println("Eating");
}
}
public class Main
{
public static void main(String[] args)
{
food f=new food();
f.eat(100000);
}
}