Skip to content

Commit 13ffea2

Browse files
committed
a reformat code
1 parent 8b16695 commit 13ffea2

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

approvaltests-util-tests/src/test/java/com/spun/util/ThrowAsErrorExamples.java

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,55 @@
44

55
import java.io.IOException;
66

7-
public class ThrowAsErrorExamples {
8-
@Test
9-
void examples() {
10-
7+
public class ThrowAsErrorExamples
8+
{
9+
@Test
10+
void examples()
11+
{
12+
}
13+
Integer whyReturnIsNeeded()
14+
{
15+
// begin-snippet: throw_as_error_does_not_compile
16+
try
17+
{
18+
return methodThatThrowsCheckedException();
1119
}
12-
Integer whyReturnIsNeeded() {
13-
// begin-snippet: throw_as_error_does_not_compile
14-
try {
15-
return methodThatThrowsCheckedException();
16-
} catch (Exception e) {
17-
ObjectUtils.throwAsError(e); // Does not compile. Missing "return" statement
18-
}
19-
// end-snippet
20-
return 0;
20+
catch (Exception e)
21+
{
22+
ObjectUtils.throwAsError(e); // Does not compile. Missing "return" statement
2123
}
22-
Integer withReturn() {
23-
// begin-snippet: throw_as_error_with_return
24-
try {
25-
return methodThatThrowsCheckedException();
26-
} catch (Exception e) {
27-
ObjectUtils.throwAsError(e);
28-
return null; // This is never reached because the line above always throws an exception
29-
}
30-
// end-snippet
24+
// end-snippet
25+
return 0;
26+
}
27+
Integer withReturn()
28+
{
29+
// begin-snippet: throw_as_error_with_return
30+
try
31+
{
32+
return methodThatThrowsCheckedException();
3133
}
32-
Integer withThrow() {
33-
// begin-snippet: throw_as_error_with_throw
34-
try {
35-
return methodThatThrowsCheckedException();
36-
} catch (Exception e) {
37-
throw ObjectUtils.throwAsError(e);
38-
}
39-
// end-snippet
34+
catch (Exception e)
35+
{
36+
ObjectUtils.throwAsError(e);
37+
return null; // This is never reached because the line above always throws an exception
4038
}
41-
42-
private Integer methodThatThrowsCheckedException() throws IOException {
43-
return 1;
39+
// end-snippet
40+
}
41+
Integer withThrow()
42+
{
43+
// begin-snippet: throw_as_error_with_throw
44+
try
45+
{
46+
return methodThatThrowsCheckedException();
47+
}
48+
catch (Exception e)
49+
{
50+
throw ObjectUtils.throwAsError(e);
4451
}
52+
// end-snippet
53+
}
54+
private Integer methodThatThrowsCheckedException() throws IOException
55+
{
56+
return 1;
57+
}
4558
}

0 commit comments

Comments
 (0)