public static void foo() throws IOException {
// some code here, when something goes wrong, you might do:
throw new IOException("error message");
}
public static void main(String[] args) {
try {
foo();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
throw new java.lang.Error("this is very bad");
throw new java.lang.RuntimeException("this is not quite as bad");
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter a number");
try {
double nb1 = kb.nextDouble();
if(nb1<0)
throw new ArithmeticException();
else System.out.println( "result : " + Math.sqrt(nb1) );
} catch (ArithmeticException e) {
System.out.println("You tried an impossible sqrt");
}
}
class Main {
public static void divideByZero() {
// throw an exception
throw new ArithmeticException("Trying to divide by 0");
}
public static void main(String[] args) {
divideByZero();
}
}
throw new java.lang.Error("this is very bad");
public static void foo() throws IOException {
// some code here, when something goes wrong, you might do:
throw new IOException("error message");
}
public static void main(String[] args) {
try {
foo();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
throw new java.lang.Error("this is very bad");
throw new java.lang.RuntimeException("this is not quite as bad");
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter a number");
try {
double nb1 = kb.nextDouble();
if(nb1<0)
throw new ArithmeticException();
else System.out.println( "result : " + Math.sqrt(nb1) );
} catch (ArithmeticException e) {
System.out.println("You tried an impossible sqrt");
}
}
class Main {
public static void divideByZero() {
// throw an exception
throw new ArithmeticException("Trying to divide by 0");
}
public static void main(String[] args) {
divideByZero();
}
}
throw new java.lang.Error("this is very bad");