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