2016-07-11 44 views
0

我正在使用StAX解析器,它使用XMLStreamReader接口。 XMLSteamReadernext將拋出XMLStreamExceptionreturn responseEntity break flow

當我回來,打破流程,使用ResponseEntity實例

例:

catch (IOException | XMLStreamException e) { 
    message = e.getMessage(); 
    log.debug(message); 
    return new ResponseEntity<String>(message, HttpStatus.BAD_REQUEST); 
} 

的消息,我得到:

[DEBUG] test.rng (No such file or directory) 

當我不回,

我收到:

[DEBUG] test.rng (No such file or directory) 
[DEBUG] "fservice/.../1.2.3/1/test.rng.xml" (Line 16): The end-tag for element type "elem" must end with a '>' delimiter. 

現在,我還需要顯示第二條消息,因爲它更具描述性。我怎樣才能做到這一點?

回答

2

這兩種情況的主要區別在於你在第一個return,而第二個在第二個。

注意,錯誤實際上是不同的:第一是說,一個文件無法找到:

[DEBUG] test.rng (No such file or directory) 

第二個是說,一個XML文件的格式不正確(且特別的結束標記,這意味着開始標記被發現,因此該文件被發現):

"fservice/.../1.2.3/1/test.rng.xml" (Line 16): The end-tag for element type "elem" must end with a '>' delimiter. 

所以第二種情況實際上是一個完全不同的問題,在第一種情況下您並未看到,因爲返回打破了控制流。

+0

但是,我檢查,它是同樣的問題,正在解決?爲什麼兩個不同的調試信息 - – psedonerd

+0

「爲什麼兩個不同的調試消息?」不知道。實際上並不清楚爲什麼第一條消息是它的原因 - 你沒有顯示'DEBUG.message'是什麼。 –

+0

所以我猜我不能回來,爲了得到相同的信息?但是這不正確嗎? – psedonerd