Dev Gupta
Dev Gupta
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
Ok
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
Ok, thank you for clearing the concept
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
This how be use throw keyword?
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
import java.util.Scanner;

public class Test extends Object{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
try{
int n=sc.nextInt();
checkIfEqualsFive(n);
}
catch(IllegalArgumentException e){
System.out.println(e);
}
sc.close();
}

public static void checkIfEqualsFive(int number) {
if (number != 5) {
throw new IllegalArgumentException("number must be five");
}
}
}
import java.util.Scanner;

public class Test extends Object{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
try{
int n=sc.nextInt();
checkIfEqualsFive(n);
}
catch(IllegalArgumentException e){
System.out.println(e);
}
sc.close();
}

public static void checkIfEqualsFive(int number) {
if (number != 5) {
throw new IllegalArgumentException("number must be five");
}
}
}
Or is this correct for the throw keyword?
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
import java.util.Scanner;

public class Test extends Object{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
checkIfEqualsFive(n);
sc.close();
}

public static void checkIfEqualsFive(int number) {
if (number != 5) {
throw new IllegalArgumentException("number must be five");
}
}
}
import java.util.Scanner;

public class Test extends Object{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
checkIfEqualsFive(n);
sc.close();
}

public static void checkIfEqualsFive(int number) {
if (number != 5) {
throw new IllegalArgumentException("number must be five");
}
}
}
Check is this correct or the other one for throw keyword
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
Ok
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
try catch
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
@ayylmao123xdd can you give example for second code
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
Ok let me do it once and get clear
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Throw and Throws
Help Please
36 replies
JCHJava Community | Help. Code. Learn.
Created by Dev Gupta on 5/5/2025 in #java-help
Thro and Throws
I want to clear the concept of Exception Handling and throw and throws i am not getting
5 replies