2016-05-15 137 views
0

當通過節奏引擎小提琴在http://fiddle.rythmengine.com/#/editororg.rythmengine.exception.CompileException:未處理的異常類型異常

下面嘗試的節奏模板代碼中,我得到的錯誤:

org.rythmengine.exception.CompileException: Unhandled exception type Exception 

我試過模板是:

@{ 
     class Field { 
      String description; 
      String getDescription() throws Exception { 
       return description; 
      } 
     } 
     Field field=new Field(); 
     field.description="test"; 
    } 

the field description is: @(field.getDescription()) 

我查看了某種try/catch結構的文檔,並諮詢了我最喜歡的搜索引擎。我沒有找到如何處理異常的提示。

在Rythm模板代碼中如何處理異常?

回答

-1

你需要確保你不會丟掉檢查的異常。你的代碼更改爲:

@{ 
     class Field { 
      String description; 
      String getDescription() throws RuntimeException { 
       return description; 
      } 
     } 
     Field field=new Field(); 
     field.description="test"; 
    } 

the field description is: @(field.getDescription()) 

,它應該工作

+0

這僅僅是一個例子。如果我不能更改我的代碼呢? –

+0

以及我看不到任何理由支持模板代碼中的CheckedException。但如果你有一個很好的理由,我可以考慮改變行爲 –