Skip to content

Commit 49fc0d8

Browse files
update exception (#200)
* update exception * fixed Serial error on gradle
1 parent 15ac95c commit 49fc0d8

16 files changed

+225
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class ArithmeticExceptionExample {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class ClassCastExceptionExample {
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class CustomExceptionExample extends Exception {
4+
5+
// @java.io.Serial
6+
private static final long serialVersionUID = 234122876006267687L;
7+
8+
public CustomExceptionExample() {
9+
super();
10+
}
11+
12+
public CustomExceptionExample(String message) {
13+
super(message);
14+
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class FinallyExample {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class IndexOutOfBoundsExceptionExample {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class NullPointerExceptionExample {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class NumberFormatExceptionExample {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.exception;
2+
3+
public class ThrowsExceptionExample {
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.examplehub.basics.exception;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class ArithmeticExceptionExampleTest {
8+
@Test
9+
void testDivideByZero() {
10+
try {
11+
int division = 10 / 0;
12+
fail();
13+
} catch (ArithmeticException e) {
14+
assertTrue(true);
15+
}
16+
}
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.examplehub.basics.exception;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
9+
class ClassCastExceptionExampleTest {
10+
@Test
11+
void testClassCast() {
12+
try {
13+
String[] strArray = new String[]{"John", "Snow"};
14+
ArrayList<String> strList = (ArrayList<String>) Arrays.asList(strArray);
15+
System.out.println("String list: " + strList);
16+
} catch (ClassCastException e) {
17+
assertTrue(true);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)