1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.base;
17
18 import static java.lang.String.format;
19
20
21
22
23
24
25
26
27
28
29
30
31 public class Exceptions {
32
33 public static IllegalStateException illegalState(Throwable cause) {
34 return new IllegalStateException(cause);
35 }
36
37 public static IllegalStateException illegalState(String msg) {
38 return new IllegalStateException(msg);
39 }
40
41 public static IllegalStateException illegalState(String msg, Object... args) {
42 return new IllegalStateException(formattedMessage(msg, args));
43 }
44
45 public static IllegalStateException illegalState(Throwable cause, String msg, Object... args) {
46 return new IllegalStateException(formattedMessage(msg, args), cause);
47 }
48
49 public static IllegalArgumentException illegalArgument(Throwable cause) {
50 return new IllegalArgumentException(cause);
51 }
52
53 public static IllegalArgumentException illegalArgument(String msg) {
54 return new IllegalArgumentException(msg);
55 }
56
57 public static IllegalArgumentException illegalArgument(String msg, Object... args) {
58 return new IllegalArgumentException(formattedMessage(msg, args));
59 }
60
61 public static IllegalArgumentException illegalArgument(Throwable cause, String msg, Object... args) {
62 return new IllegalArgumentException(formattedMessage(msg, args), cause);
63 }
64
65 protected static String formattedMessage(String msg, Object... args) {
66 if (args == null || args.length == 0) {
67 return msg;
68 } else {
69 return format(msg, args);
70 }
71 }
72
73 }