/
MethodsThrowingExceptions.java
39 lines (34 loc) · 1.2 KB
/
MethodsThrowingExceptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.IOException;
public class MethodsThrowingExceptions {
boolean isCapitalizedThrowingRuntimeException(String s) {
if (s == null) {
throw new RuntimeException("Null String");
}
if (s.equals("")) {
return true;
}
String first = s.substring(0, 1);
String rest = s.substring(1);
return first.equals(first.toUpperCase()) && rest.equals(rest.toLowerCase());
}
boolean isCapitalizedThrowingSpecializedException(String s) {
if (s == null) {
throw new NullPointerException();
}
if (s.equals("")) {
return true;
}
String first = s.substring(0, 1);
String rest = s.substring(1);
return first.equals(first.toUpperCase()) && rest.equals(rest.toLowerCase());
}
private void methodThrowingBasicException() throws Exception {
System.out.println("Method throwing Exception");
}
private void methodThrowingIOException() throws IOException {
System.out.println("Method throwing IOException");
}
private void methodThrowingThrowable() throws Throwable {
System.out.println("Method throwing Throwable");
}
}