ExceptionTest.java





import java.io.*;

//사용자 정의 예외클래스 만들기.
class MyException extends Exception{
public String msg=null;
public MyException(String msg){
this.msg = msg;
}
}

/**
* @author Administrator
*
*/
public class ExceptionTest {
public int myMath(int a, int b) throws MyException{
if(b==0){
MyException my = new MyException("숫자 0으로는 나눌수 없습니다.");
throw my;
}else{
int c =0;
c = a/b;
return c;
}
}
public static void main(String[] args) {
ExceptionTest ex = new ExceptionTest();
try{
ex.myMath(20, 0);
}catch(MyException e){
System.out.println("예외발생 : "+ e.msg);
}
}
}






/*
public class ExceptionTest {

public static void main(String[] args){
//만약에 파일을 카피하거나 네트워크 전송할때.
//FileInputStream fis = new FileInputStream("c:\\test\\aaa.txt");

//문자로 읽어보기, 파일카피, 네트워크 전송
//FileReader fr = new FileReader("c:\\test\\aaa.txt");
FileReader fr=null;
BufferedReader br=null;
try{
fr = new FileReader("c:\\Test\\aaa.txt");
br = new BufferedReader(fr);
char data[] = new char[512];
// while(fr.read(data)!= -1){
// System.out.println(data);
// }
String line= null;
while((line = br.readLine())!=null){
System.out.println(line);
}

// int read = fr.read();
// System.out.println((char)read);
}catch(FileNotFoundException e){
System.out.println("해당 디렉토리나 파일이 없습니다.");
}catch(IOException e){
System.out.println("파일을 읽을수 없습니다.");
}catch(Exception e){
System.out.println("알수 없는 예외입니다.");
}finally{
try{
if(fr != null) fr.close();
}catch(Exception e){}
}
}
}


*/



.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2009/10/06 18:20 2009/10/06 18:20
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/4689

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/4689

« Previous : 1 : ... 1755 : 1756 : 1757 : 1758 : 1759 : 1760 : 1761 : 1762 : 1763 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Statistics Graph

Site Stats

Total hits:
196758
Today:
503
Yesterday:
673