2012-06-21 23 views
1

可能重複的做法:
Java: Global Exception Handler最好在Java PROGRAMM記錄未捕獲的異常

我認爲是這樣的:

public static void main(String[] args) { 
    try { 
    startOfMyProg(); 
    } catch (RuntimeException e) { 
    log.error(e.toString()); 
    // Maybe rethrow it so i can see it in the console? 
    } 
} 

這是一個簡單的解決方案, 我知道。也許有人知道一個更好的?

問候& & TIA noircc

+2

那麼你可以只用'Exception'或'Throwable'更好的結果購買。一些異常會通過運行時異常。 – Thihara

回答

3

我會

} catch (Throwable e) { 
    log.error("Uncaught exception", e); // prints the stack trace.