简体   繁体   English

错误捕捉/错误处理

[英]Error Catching / Error Handling

I need to catch or print the error in the else . 我需要在else捕获或打印错误。

Below is my code: 下面是我的代码:

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!");
}

Maybe something like this? 也许是这样的吗?

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!");
} 

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM