Java
#037 자바 Try개념
Ahn_Bo
2020. 12. 10. 11:55
try 는 한 번 시도해보다~ 라는 개념
if (command.startsWtih("article search")) {
int inputedId = Integer.parseInt(command.split(" ")[2]);
}
//이 코드를 작성할 시 오류가 나기에 이 코드를 아래와 같이 바꿈
if (command.startWith("article search")) {
int inputedId = 0;
try {
int inputedId = Integer.parseInt(command.split(" ")[2]);
}
catch ( NumberFormatException e ) {
System.out.println("숫자써라 제발");
continue;
}
// 즉 try 안에 있는 코드가 오류가 났을 때, catch 안에 있는 내용을 보여주겠다.
// 내 선에서 해결하겠다. 라는 뜻
*전체적인 일상은 노션을 통해 작성하고 있습니다.