Exception이 생기면 어떻게 되는지 궁금해 하는 분이 계시던데.. 기본적인 것이고, thinking in java를 꼭 정독하면 좋겠다.

 

아래의 코드를 보자

 

 



import org.junit.Test;


import com.opensymphony.xwork.interceptor.annotations.After;
import com.opensymphony.xwork.interceptor.annotations.Before;


public class TestCase {

 int a = 0;
 @Before
 public void setup() throws Exception {

 }
 
 @After
 public void teardown() throws Exception {
  
 }
 
 public void a() {
  a = 0;
  try {
   a = 1;
   throw new Exception ("1");
  } catch (Exception e) {
   a = 2;
  }
  a = 3;
 }
 
 @Test
 public void execute() throws Exception {
  a();
  System.out.println(a);
 }
 
}

 

 

 

3이 출력된다.

java 언어는 예외처리 개념을 두었는데(여기에 대한 엄청난 의견들이 있음..) catch로 묶는 순간 이미 이것은 처리를 하겠다는 개념으로 생각하면 됨.

'java core' 카테고리의 다른 글

Java Memory 이야기  (0) 2009.03.25
svn과 연동 (svnkit)  (0) 2009.03.25
PermGen에서의 OutOfMemoryError 발생 대처하기  (0) 2009.02.25
Generic Erasure  (0) 2009.02.24
Java Profiling API 공부 시작..  (0) 2009.02.20
Posted by '김용환'
,