diff --git a/castingandothers/src/main/java/com/example/Main.java b/castingandothers/src/main/java/com/example/Main.java index e92a0f8..d88e138 100644 --- a/castingandothers/src/main/java/com/example/Main.java +++ b/castingandothers/src/main/java/com/example/Main.java @@ -8,6 +8,30 @@ public class Main { SERGEANT, CAPTAIN } + + static int div(int a, int b) throws ArithmeticException { + if(b == 0) { + throw new ArithmeticException("Division by Zero"); + } else { + return a / b; + } + } + + static class FirstException extends Exception { } + static class SecondException extends Exception { } + + public void rethrowException(String exceptionName) throws Exception { + try { + if (exceptionName.equals("First")) { + throw new FirstException(); + } else { + throw new SecondException(); + } + } catch (Exception e) { + throw e; + } + } + public static void main(String[] args) { System.out.println("Hello world!"); @@ -68,6 +92,16 @@ public class Main { // Once you locate the package you want to use, you need to import it into your code. + + //Exception Handeling + try{ + int an = 0 / 0; + }catch (Exception e){ + System.out.println("Here was an error: " + e); + } + System.out.println(div(42, 0)); + + //https://docs.oracle.com/javase/8/docs/technotes/guides/language/catch-multiple.html } } \ No newline at end of file diff --git a/castingandothers/target/classes/com/example/Main$1.class b/castingandothers/target/classes/com/example/Main$1.class index bfcd1db..a1415bb 100644 Binary files a/castingandothers/target/classes/com/example/Main$1.class and b/castingandothers/target/classes/com/example/Main$1.class differ diff --git a/castingandothers/target/classes/com/example/Main$FirstException.class b/castingandothers/target/classes/com/example/Main$FirstException.class new file mode 100644 index 0000000..99ac4f9 Binary files /dev/null and b/castingandothers/target/classes/com/example/Main$FirstException.class differ diff --git a/castingandothers/target/classes/com/example/Main$SecondException.class b/castingandothers/target/classes/com/example/Main$SecondException.class new file mode 100644 index 0000000..7210d71 Binary files /dev/null and b/castingandothers/target/classes/com/example/Main$SecondException.class differ diff --git a/castingandothers/target/classes/com/example/Main.class b/castingandothers/target/classes/com/example/Main.class index 4da7236..6032a15 100644 Binary files a/castingandothers/target/classes/com/example/Main.class and b/castingandothers/target/classes/com/example/Main.class differ