|
19 | 19 | void errExit(int returnCode, const std::string &errorMsg); |
20 | 20 |
|
21 | 21 | void activateSolver(std::ifstream& inputFileStream, FILE* outputFile, int taskID) { |
| 22 | + int returnCode = 0; |
| 23 | + std::string errorMsg; |
| 24 | + VCellSolver* targetSolver; |
| 25 | + // First try block - create the solver; failure => no need to delete targetSolver! |
22 | 26 | try { |
23 | | - VCellSolver* targetSolver = VCellSolverFactory::produceVCellSolver(inputFileStream, taskID); |
24 | | - targetSolver->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested); |
| 27 | + targetSolver = VCellSolverFactory::produceVCellSolver(inputFileStream, taskID); |
25 | 28 | } catch (const char *ex) { |
26 | | - errExit(-1, ex); |
| 29 | + returnCode = -1; |
| 30 | + errorMsg = ex; |
| 31 | + targetSolver = nullptr; |
27 | 32 | } catch (std::string &ex) { |
28 | | - errExit(-2, ex); |
| 33 | + returnCode = -2; |
| 34 | + errorMsg = ex; |
| 35 | + targetSolver = nullptr; |
29 | 36 | } catch (StoppedByUserException&) { |
30 | | - errExit(0, "Execution Stopped By User"); |
| 37 | + returnCode = 0; |
| 38 | + errorMsg = "Execution Stopped By User"; |
| 39 | + targetSolver = nullptr; |
31 | 40 | } catch (VCell::Exception &ex) { |
32 | | - errExit(-3, ex.getMessage()); |
| 41 | + returnCode = -3; |
| 42 | + errorMsg = ex.getMessage(); |
| 43 | + targetSolver = nullptr; |
33 | 44 | } catch (const std::exception& err) { |
34 | | - errExit(-4, err.what()); |
| 45 | + returnCode = -4; |
| 46 | + errorMsg = err.what(); |
| 47 | + targetSolver = nullptr; |
35 | 48 | } catch (...) { |
36 | | - errExit(-5, "unknown error"); |
| 49 | + returnCode = -5; |
| 50 | + errorMsg = "Unknown Error Detected"; |
| 51 | + targetSolver = nullptr; |
| 52 | + } |
| 53 | + // second try block - solver is created; must delete it! |
| 54 | + if (nullptr != targetSolver) { |
| 55 | + try { |
| 56 | + targetSolver->solve(nullptr, true, outputFile, VCellSundialsSolver::checkStopRequested); |
| 57 | + } catch (const char *ex) { |
| 58 | + returnCode = -1; |
| 59 | + errorMsg = ex; |
| 60 | + // errExit(-1, ex); |
| 61 | + } catch (std::string &ex) { |
| 62 | + returnCode = -2; |
| 63 | + errorMsg = ex; |
| 64 | + } catch (StoppedByUserException&) { |
| 65 | + returnCode = 0; |
| 66 | + errorMsg = "Execution Stopped By User"; |
| 67 | + } catch (VCell::Exception &ex) { |
| 68 | + returnCode = -3; |
| 69 | + errorMsg = ex.getMessage(); |
| 70 | + } catch (const std::exception& err) { |
| 71 | + returnCode = -4; |
| 72 | + errorMsg = err.what(); |
| 73 | + } catch (...) { |
| 74 | + returnCode = -5; |
| 75 | + errorMsg = "Unknown Error Detected"; |
| 76 | + } |
| 77 | + // !!! DELETE THE SOLVER !!! |
| 78 | + delete targetSolver; |
37 | 79 | } |
38 | 80 |
|
39 | 81 | // cleanup |
40 | 82 | if (SimulationMessaging::getInstVar() != nullptr) { |
41 | 83 | SimulationMessaging::getInstVar()->waitUntilFinished(); |
42 | 84 | delete SimulationMessaging::getInstVar(); |
43 | 85 | } |
| 86 | + |
| 87 | + if (!errorMsg.empty()) errExit(returnCode, errorMsg); |
44 | 88 | } |
45 | 89 |
|
46 | 90 | void errExit(int returnCode, const std::string &errorMsg) { |
|
0 commit comments