[JAVA-12620] Split core-java-exceptions module

This commit is contained in:
Haroon Khan
2022-06-14 21:56:25 +01:00
parent e31a4dff8d
commit 18bcb72f85
8 changed files with 30 additions and 18 deletions

View File

@@ -9,9 +9,9 @@ This module contains articles about core java exceptions
- [Exception Handling in Java](https://www.baeldung.com/java-exceptions)
- [Differences Between Final, Finally and Finalize in Java](https://www.baeldung.com/java-final-finally-finalize)
- [Difference Between Throw and Throws in Java](https://www.baeldung.com/java-throw-throws)
- [“Sneaky Throws” in Java](https://www.baeldung.com/java-sneaky-throws)
- [The StackOverflowError in Java](https://www.baeldung.com/java-stack-overflow-error)
- [Checked and Unchecked Exceptions in Java](https://www.baeldung.com/java-checked-unchecked-exceptions)
- [Common Java Exceptions](https://www.baeldung.com/java-common-exceptions)
- [Will an Error Be Caught by Catch Block in Java?](https://www.baeldung.com/java-error-catch)
- [[Next -->]](/core-java-modules/core-java-exceptions-2)
- [[Next -->]](../core-java-exceptions-2)
-

View File

@@ -21,12 +21,6 @@
<artifactId>mail</artifactId>
<version>${javax.mail.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>

View File

@@ -1,22 +0,0 @@
package com.baeldung.exceptions.sneakythrows;
import java.io.IOException;
import lombok.SneakyThrows;
public class SneakyThrowsExamples {
public static <E extends Throwable> void sneakyThrow(Throwable e) throws E {
throw (E) e;
}
public static void throwSneakyIOException() {
sneakyThrow(new IOException("sneaky"));
}
@SneakyThrows
public static void throwSneakyIOExceptionUsingLombok() {
throw new IOException("lombok sneaky");
}
}

View File

@@ -1,28 +0,0 @@
package com.baeldung.exceptions.sneakythrows;
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOException;
import static com.baeldung.exceptions.sneakythrows.SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import org.junit.Test;
public class SneakyThrowsExamplesUnitTest {
@Test
public void throwSneakyIOException_IOExceptionShouldBeThrown() {
assertThatThrownBy(() -> throwSneakyIOException())
.isInstanceOf(IOException.class)
.hasMessage("sneaky")
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOException");
}
@Test
public void throwSneakyIOExceptionUsingLombok_IOExceptionShouldBeThrown() {
assertThatThrownBy(() -> throwSneakyIOExceptionUsingLombok())
.isInstanceOf(IOException.class)
.hasMessage("lombok sneaky")
.hasStackTraceContaining("SneakyThrowsExamples.throwSneakyIOExceptionUsingLombok");
}
}