MAIN
여행
지식
낙서연구
Q&A
정보구름
 



L I N K S
KURAPA.COM MAPS
세고비아 길버드 Blog
홈미디어센타 X-Revo
고구마킬러 ㄲㅏㄲㅣ
DaDa의 원초적 잡화
아하! 무진장 알뜰정보
바조의 짜바스크립
일하는엄마 - 워킹맘
네이버,구글맵 지도 검색
세상을 살아가며 궁금한것들
CTICKET - 인생의 쿠폰
Super Coder's Page
똑똑한 검색 ReportBank
MSN Web Messenger
포토웤스(PHOTOWORKS)

믹시
Scouter for KURAPA.COM

0


Translator
Francais (French) Deutsch (German) Espanol (Spanish) Italiano (Italian) Portugues (Portugese) 日本語 (Japanese) 한국말 (Korean) ??中文 (Chinese) العربية (Arabic) Русский язык (Russian) English



> Q&A > Groovy
전체글 수: 12
요즘 뜬다는 그루비(Groovy)... 함께 심층 분석 해보세
이클립스IDE :: 그루비 플러그인 :: Exception 메시지 팁
2008-07-11 11:11:41

이클립스에서 플러그인을 설치하여 그루비를 사용중이라면 exception 내용이 필요없이 너무 많아서 골머리를 앓고 있을 것이다.

예를 들면 다음코드를 보자.

def onPurposeException() {
     new File('noexitfile.txt').eachLine {
         println it
     }
}
 
onPurposeException()

이 코드를 이클립스에서 실행한 후 콘솔창을 보면 결과가 다음과 같이 나온다.

보시다시피 정작 필요한 메시지는 19번째 라인에 있다. 나머지는 그루비 개발자에게는 필요없는 메시지다.

   1: Exception in thread "main" java.io.FileNotFoundException: noexitfile.txt (지정된 파일을 찾을 수 없습니다)
   2:     at java.io.FileInputStream.open(Native Method)
   3:     at java.io.FileInputStream.<init>(Unknown Source)
   4:     at groovy.util.CharsetToolkit.<init>(CharsetToolkit.java:68)
   5:     at org.codehaus.groovy.runtime.DefaultGroovyMethods.newReader(DefaultGroovyMethods.java:7499)
   6:     at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachLine(DefaultGroovyMethods.java:6797)
   7:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   8:     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   9:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  10:     at java.lang.reflect.Method.invoke(Unknown Source)
  11:     at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:51)
  12:     at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)
  13:     at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
  14:     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
  15:     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
  16:     at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:761)
  17:     at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:749)
  18:     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
  19:     at Test.onPurposeException(Test.groovy:12)
  20:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  21:     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  22:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  23:     at java.lang.reflect.Method.invoke(Unknown Source)
  24:     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
  25:     at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
  26:     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
  27:     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:77)
  28:     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrent0(ScriptBytecodeAdapter.java:109)
  29:     at Test.run(Test.groovy:17)
  30:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  31:     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  32:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  33:     at java.lang.reflect.Method.invoke(Unknown Source)
  34:     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
  35:     at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
  36:     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
  37:     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
  38:     at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:773)
  39:     at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:753)
  40:     at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:402)
  41:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  42:     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  43:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  44:     at java.lang.reflect.Method.invoke(Unknown Source)
  45:     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
  46:     at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
  47:     at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1077)
  48:     at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:744)
  49:     at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
  50:     at Test.main(Test.groovy)

이렇게 필요없는 메시지를 제고하고 보고 싶다면 다음 함수를 추가해서 사용하기 바란다.

def pst(e){
    def newTrace = []
    e.stackTrace.each{te->
        if (te.toString() =~ /.*groovy:\d*/) newTrace << te
    }
    e.stackTrace = newTrace
    e.printStackTrace()
}

위 함수를 이용하여  try catch문을 적용해 보자.

try {
    onPurposeException()
} catch(Exception _) {
    pst(_)
}

결과는 아래와 같이 깔끔하게 나온다.
보시다시피 어느 라인에서 문제가 발생하는지 한눈에 알아볼 수 있다.

java.io.FileNotFoundException: noexitfile.txt (지정된 파일을 찾을 수 없습니다)
    at Test.onPurposeException(Test.groovy:12)
    at Test.run(Test.groovy:20)

이클립스 그루비 플러그인은 아직도 개발중인 상태인데 약간 더딘 감이 있다.

다음 버전에서는 더 좋은 기능을 기대해 보기로 하자.

 

Reference : 그루비 이클립스 플러그인 FAQ

2008.06.25 by gilbird



태그 : 그루비 , 이클립스
추천 : 0, 조회 : 1,410
코멘트 0 | 트랙백 0 | 첨부파일 1
글자의 색상을 지정합니다 글자의 배경색상을 지정합니다
글자를 진하게 합니다 글자를 기울이게 합니다 밑줄을 긋습니다 취소선을 긋습니다
link를 만듭니다 이미지를 추가합니다 동영상/플래쉬등을 추가합니다 html 코드를 직접 입력합니다
이모티콘을 추가합니다 글박스를 만들거나 글숨김 기능을 추가합니다 html 코드를 직접 입력합니다
html모드로 변환합니다.
 
번호
제목
글쓴이
일자
추천
조회
12
2008-08-04
0
478
11
2008-07-11
0
1,411
10
2008-07-11
0
338
9
2008-07-11
0
330
8
2008-07-11
0
324
7
2008-07-11
0
303
6
2008-07-11
0
292
5
2008-07-11
0
639
4
2008-07-11
0
300
3
2008-07-11
0
384
2
2008-03-29
0
609
1
2008-03-28
0
470


 
Copyright 2000-2008 KURAPA.COM All Rights Reserved.