595
No
class FileError
package java14;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class FileError {
int[] list;
static final int SIZE =10;
public FileError(){
list=new int[SIZE];
for(int i=0; i
class ThrowsTest
package java14;
// try ~ catch ~ finally : method 의 일부분
//throws : method 전체
//인터럽트 : CPU 간섭
public class ThrowsTest {
public static void main(String[] args) throws InterruptedException {
for(int i=1; i<=10; i++){
System.out.println(i);
Thread.sleep(10);
/* try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}*/
}
}
}
class MyException
package java14;
//사용자정의 예외 : Exception 을 오버라이딩
class MyException extends Exception{
public MyException() { //생성자
super("사용자 정의 예외"); // 상위클래스의 생성자 호출
}
}
// throw : 예외를 인위적으로 발생시킴
public class ExceptionTest1 {
public static void main(String[] args) throws MyException{
int a =10;
if(a==10){
throw new MyException();
}
}
}
댓글 ( 4)
댓글 남기기