有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将多个trycatch块组合成一个

下面是一个示例代码块

// rebuild session state for test, need the current phase first
String phaseName = testtaker.getPhase();
TestPhase phase = null;

try {
    phase = objFactory.getPhase(testtaker.getTestengine(), phaseName);
} catch (Exception e) {
    log.error("Exception when getting phase for testtaker.", e);
    CaslsUtils.outputLoggingData(log_, request);
    // Toss the exception back to the engine, add a message
    throw new Exception("Cannot create phase: " + phaseName);
}

try {
    // Adding this code to improve the performance of the application during student login
    Testtaker newTestTaker = objFactory.getDataAccessor().getTesttakerByTestTakerId(testtaker.getTesttakerid());// This will populate testtaker object with all its child table records
    if(newTestTaker != null) {
        session.setAttribute(ConstantLibrary.SESSION_TESTTAKER, newTestTaker);
    }
    phase.rebuildTest(session);
} catch (Exception e) {
    log.error("Exception when calling rebuildTest.", e);
    CaslsUtils.outputLoggingData(log_, request);
    // Toss the exception back to the engine, add a message
    throw new Exception("Cannot Rebuild Test");
}

请帮助我如何将这段代码组合到一个multi-catch语句中,因为当我尝试这样做时,它会在第二个catch块中生成错误作为无法访问的代码


共 (0) 个答案