JAVA-24938 Article Code Matches first commit (#14820)

This commit is contained in:
anuragkumawat 2023-10-21 14:27:49 +05:30 committed by GitHub
parent adb490c874
commit b0ed62e8c8
5 changed files with 38 additions and 4 deletions

View File

@ -20,8 +20,9 @@ public class Main {
System.out.println("General exception"); System.out.println("General exception");
} }
checkedException(); checkedExceptionWithTryCatch();
checkedExceptionWithThrows(); checkedExceptionWithThrows();
divideByZero();
} }
private static void checkedExceptionWithThrows() throws FileNotFoundException { private static void checkedExceptionWithThrows() throws FileNotFoundException {
@ -29,7 +30,7 @@ public class Main {
FileInputStream stream = new FileInputStream(file); FileInputStream stream = new FileInputStream(file);
} }
private static void checkedException() { private static void checkedExceptionWithTryCatch() {
File file = new File("not_existing_file.txt"); File file = new File("not_existing_file.txt");
try { try {
FileInputStream stream = new FileInputStream(file); FileInputStream stream = new FileInputStream(file);
@ -37,5 +38,11 @@ public class Main {
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void divideByZero() {
int numerator = 1;
int denominator = 0;
int result = numerator / denominator;
}
} }

View File

@ -0,0 +1,8 @@
package com.baeldung.exceptions.throwvsthrows;
public class NullOrEmptyException extends RuntimeException {
public NullOrEmptyException(String errorMessage) {
super(errorMessage);
}
}

View File

@ -14,7 +14,7 @@ public class BuilderWithDefaultValueUnitTest {
} }
@Test @Test
public void givenBuilderWithDefaultValue_NoArgsWorksAlso() { public void givenBuilderWithDefaultValue_ThanNoArgsWorksAlso() {
Pojo build = new Pojo().toBuilder() Pojo build = new Pojo().toBuilder()
.build(); .build();
Pojo pojo = new Pojo(); Pojo pojo = new Pojo();

View File

@ -8,6 +8,6 @@ public class SwaggerController {
@RequestMapping("/myproject") @RequestMapping("/myproject")
public String getRedirectUrl() { public String getRedirectUrl() {
return "redirect:swagger-ui.html"; return "redirect:swagger-ui/";
} }
} }

View File

@ -0,0 +1,19 @@
package com.baeldung.ex.beancreationexception.cause9;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config {
@Autowired
BeanFactory beanFactory;
@Bean
public BeanB beanB() {
beanFactory.getBean("beanA");
return new BeanB();
}
}