1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.corpus;
15
16 import java.util.Random;
17
18 import javax.management.remote.JMXProviderException;
19
20 public class ExceptionBuilder {
21
22 static Throwable build(Random r, double nestingProbability) {
23 double rn = r.nextDouble();
24 boolean nested = false;
25 if (rn < nestingProbability) {
26 nested = true;
27 }
28
29 Throwable cause = null;
30 if (nested) {
31 cause = makeThrowable(r, null);
32 }
33 return makeThrowable(r, cause);
34 }
35
36 private static Throwable makeThrowable(Random r, Throwable cause) {
37 int exType = r.nextInt(4);
38 switch (exType) {
39 case 0:
40 return new IllegalArgumentException("an illegal argument was passed", cause);
41 case 1:
42 return new Exception("this is a test", cause);
43 case 2:
44 return new JMXProviderException("jmx provider exception error occured", cause);
45 case 3:
46 return new OutOfMemoryError("ran out of memory");
47 }
48 return null;
49 }
50
51 }