try catch 用法
try裡的敍述句有可能會丟出例外資訊 ( Exception ) ,
而丟出的例外資訊 ( Exception ) 型態就可以由catch來取得,做適當的處理。
一般有需要的話會在try catch後面放個finally,通常用來關閉或則除物件等。
try {
/* 執行外部軟體cmd */
Runtime.getRuntime().exec(cmd).waitFor();
/* check output file is exists */
Path filePath = Paths.get(outputFilePath);
/* 如果exists的話 */
if (filePath.toFile().exists()) {
System.out.println("convertPdf Done");
/* 例外Throwable */
} else {
throw new Throwable();
}
/* 例外處理 */
} catch (Throwable t) {
System.out.println("convertPdf t:" + t.toString());
throw t;
}