Java 错误捕获/错误处理

Java 错误捕获/错误处理,java,error-handling,Java,Error Handling,我需要捕获或打印else中的错误 下面是我的代码: private static void runProcess(String command) throws Exception { Process pro = Runtime.getRuntime().exec(command); printLines(command + " stdout:", pro.getInputStream()); // For RUN output only pro.waitFor();

我需要捕获或打印
else
中的错误

下面是我的代码:

private static void runProcess(String command) throws Exception {
    Process pro = Runtime.getRuntime().exec(command);
    printLines(command + " stdout:", pro.getInputStream()); // For RUN output only
    pro.waitFor();
    if (pro.exitValue() == 0) 
    {
        System.out.println("Status: COMPILATION SUCCESSFULL!!");
        // sendFile(); // to code checker
        sendFile();
        System.out.println("File Sent!");

    } else
        System.out.println("Syntax Error Found!");
}

也许是这样的

private static void runProcess(String command) throws Exception {
try{
    Process pro = Runtime.getRuntime().exec(command);
    printLines(command + " stdout:", pro.getInputStream()); // For RUN output only
    pro.waitFor();
    if (pro.exitValue() == 0) {
        System.out.println("Status: COMPILATION SUCCESSFULL!!");
        // sendFile(); // to code checker
        sendFile();
        System.out.println("File Sent!");
    }

}catch(Exception e){
//Your exception message here, handle it as you want
  System.out.println(e.getMessage());
  System.out.println("Syntax Error Found!");
} 

}

有什么问题吗?@SamiTahri我需要捕捉错误并打印出来。但是当我尝试在try块中插入if语句时,catch没有打印错误预期的错误是什么?请尝试使用上层类异常,
catch(Throwable th){