Skip to content

Commit a461548

Browse files
committed
Improved exception handling.
See issue #55
1 parent a6d37b4 commit a461548

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

Diff for: src/main/java/net/finmath/montecarlo/process/ProcessEulerScheme.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private void doPrecalculateProcess() {
180180
drift = getDrift(timeIndex - 1, discreteProcess[timeIndex - 1], null);
181181
}
182182
catch(Exception e) {
183-
throw new RuntimeException("Drift calculaton failed at time " + getTime(timeIndex - 1) + ". See cause for details.", e);
183+
throw new RuntimeException("Drift calculaton failed at time index " + timeIndex + " (time=" + getTime(timeIndex - 1) + ") . See cause of this exception for details.", e);
184184
}
185185

186186
// Calculate new realization
@@ -228,12 +228,14 @@ public RandomVariableInterface call() {
228228
* Optional multi-threadding (asyncronous calculation of the components)
229229
*/
230230
Future<RandomVariableInterface> result = null;
231-
if(isUseMultiThreadding) {
232-
result = executor.submit(worker);
233-
} else {
234-
try {
231+
try {
232+
if(isUseMultiThreadding) {
233+
result = executor.submit(worker);
234+
} else {
235235
result = new FutureWrapper<>(worker.call());
236-
} catch (Exception e) {}
236+
}
237+
} catch (Exception e) {
238+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
237239
}
238240

239241
// The following line will add the result of the calculation to the vector discreteProcessAtCurrentTimeIndex
@@ -250,11 +252,9 @@ public RandomVariableInterface call() {
250252
discreteProcess[timeIndex][componentIndex] = null;
251253
}
252254
} catch (InterruptedException e) {
253-
// TODO Auto-generated catch block
254-
e.printStackTrace();
255+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
255256
} catch (ExecutionException e) {
256-
// TODO Auto-generated catch block
257-
e.printStackTrace();
257+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
258258
}
259259
}
260260

@@ -294,7 +294,6 @@ public RandomVariableInterface call() {
294294
}
295295
}
296296

297-
298297
/**
299298
* Reset all precalculated values
300299
*/

Diff for: src/main/java6/net/finmath/montecarlo/process/ProcessEulerScheme.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import net.finmath.concurrency.FutureWrapper;
1818
import net.finmath.montecarlo.BrownianMotionInterface;
1919
import net.finmath.montecarlo.IndependentIncrementsInterface;
20-
import net.finmath.optimizer.SolverException;
2120
import net.finmath.stochastic.RandomVariableInterface;
2221

2322
/**
@@ -52,7 +51,7 @@ public class ProcessEulerScheme extends AbstractProcess {
5251

5352
public enum Scheme {
5453
EULER, PREDICTOR_CORRECTOR, EULER_FUNCTIONAL
55-
};
54+
}
5655

5756
private IndependentIncrementsInterface stochasticDriver;
5857

@@ -181,7 +180,7 @@ private void doPrecalculateProcess() {
181180
drift = getDrift(timeIndex - 1, discreteProcess[timeIndex - 1], null);
182181
}
183182
catch(Exception e) {
184-
throw new RuntimeException("Drift calculaton failed at time " + getTime(timeIndex - 1), e);
183+
throw new RuntimeException("Drift calculaton failed at time index " + timeIndex + " (time=" + getTime(timeIndex - 1) + ") . See cause of this exception for details.", e);
185184
}
186185

187186
// Calculate new realization
@@ -198,7 +197,7 @@ private void doPrecalculateProcess() {
198197
}
199198

200199
Callable<RandomVariableInterface> worker = new Callable<RandomVariableInterface>() {
201-
public RandomVariableInterface call() throws SolverException {
200+
public RandomVariableInterface call() {
202201
if(scheme == Scheme.EULER_FUNCTIONAL) {
203202
currentState[componentIndex] = applyStateSpaceTransformInverse(componentIndex, discreteProcess[timeIndex - 1][componentIndex]);
204203
}
@@ -229,12 +228,14 @@ public RandomVariableInterface call() throws SolverException {
229228
* Optional multi-threadding (asyncronous calculation of the components)
230229
*/
231230
Future<RandomVariableInterface> result = null;
232-
if(isUseMultiThreadding) {
233-
result = executor.submit(worker);
234-
} else {
235-
try {
236-
result = new FutureWrapper<RandomVariableInterface>(worker.call());
237-
} catch (Exception e) {}
231+
try {
232+
if(isUseMultiThreadding) {
233+
result = executor.submit(worker);
234+
} else {
235+
result = new FutureWrapper<>(worker.call());
236+
}
237+
} catch (Exception e) {
238+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
238239
}
239240

240241
// The following line will add the result of the calculation to the vector discreteProcessAtCurrentTimeIndex
@@ -251,11 +252,9 @@ public RandomVariableInterface call() throws SolverException {
251252
discreteProcess[timeIndex][componentIndex] = null;
252253
}
253254
} catch (InterruptedException e) {
254-
// TODO Auto-generated catch block
255-
e.printStackTrace();
255+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
256256
} catch (ExecutionException e) {
257-
// TODO Auto-generated catch block
258-
e.printStackTrace();
257+
throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
259258
}
260259
}
261260

@@ -295,7 +294,6 @@ public RandomVariableInterface call() throws SolverException {
295294
}
296295
}
297296

298-
299297
/**
300298
* Reset all precalculated values
301299
*/

0 commit comments

Comments
 (0)