码迷,mamicode.com
首页 > 其他好文 > 详细

异常课——抛出

时间:2016-09-26 14:37:16      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

package class10923;
									//异常课件例题——抛出
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.synth.SynthScrollBarUI;

public class yichangpaochu {
												//抛出语句
	public static void main(String[] args) //throws FileNotFoundException 
	{
		// TODO Auto-generated method stub

		//访问文件
//		File file=new File("d:/a.test");
		//使用输入流打开文件
//		FileInputStream in =new FileInputStream(file);
		
//		
//			try {
//				System.out.println(chufa(12, 0));
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//				System.out.println("错误");
//			}

	}
	
	//抛出异常的方法
	public static int chufa(int a,int b) throws Exception
	{
//		if(b==0)
//		{
//			//抛出异常语句
//			//Exceptin的实例
//			throw new Exception("你传的参数b不能等于0");
//		}
		int rtn=0;
		try
		{
			rtn=a/b;
		}
		catch(Exception e)
		{
			//记录异常信息
			
			//继续抛出
			throw e;
		}
		return rtn;
//		return a/b;
	}

}

  

异常课——抛出

标签:

原文地址:http://www.cnblogs.com/zhangnaitao/p/5908927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!