-
Notifications
You must be signed in to change notification settings - Fork 0
Exceptions #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Exceptions #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module type="JAVA_MODULE" version="4"> | ||
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
| <exclude-output /> | ||
| <content url="file://$MODULE_DIR$"> | ||
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
| </content> | ||
| <orderEntry type="jdk" jdkName="openjdk-24" jdkType="JavaSDK" /> | ||
| <orderEntry type="sourceFolder" forTests="false" /> | ||
| </component> | ||
| </module> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import javax.naming.AuthenticationException; | ||
| import java.io.FileNotFoundException; | ||
| import java.net.BindException; | ||
| import java.util.*; | ||
|
|
||
| public class Main { | ||
| public static Scanner sc = new Scanner(System.in); | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| Exception runTimeException = new RuntimeException("an error occured"); | ||
| Exception indexOutOfBoundsException = new IndexOutOfBoundsException("Index out of bounds"); | ||
|
|
||
| try { | ||
| //exeptions(); | ||
| } catch (Exception runTime) { | ||
| System.err.println(runTime); | ||
| } | ||
| //Programm(); | ||
| //ex_3(); | ||
| ex_4(1); | ||
| ex_5(2); | ||
| ex_6(6); | ||
| ex_7(); | ||
| ex_8(); | ||
| } | ||
|
|
||
| public static void exeptions(Exception runTimeException, Exception indexOutOfBoundsException) throws Exception { | ||
|
|
||
| indexOutOfBoundsException.getStackTrace(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this just gets the stack trace it doesn't print it |
||
| throw runTimeException; | ||
| } | ||
|
|
||
| public static void Programm() { | ||
| try { | ||
| int[] arr = new int[5]; | ||
| arr[6] = 7; | ||
| } catch (RuntimeException runTimeException) { | ||
| System.out.println("an error occured"); | ||
| } | ||
| } | ||
|
|
||
| public static void ex_3() { | ||
| for (int i = 0; i > -1; i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use for and not use the index instead of using while? |
||
| int num = sc.nextInt(); | ||
| if (num == 45) { | ||
| try { | ||
| throw new IllegalArgumentException(); | ||
| } catch (IllegalArgumentException runTimeException) { | ||
| } | ||
| } | ||
| if (num == 100) { | ||
| throw new RuntimeException(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void ex_4(int num) throws FileNotFoundException, BindException, AuthenticationException { | ||
| if (num == 1) { | ||
| throw new FileNotFoundException(); | ||
| } else if (num == 2) { | ||
| throw new BindException(); | ||
| } else if (num == 3) { | ||
| throw new AuthenticationException(); | ||
| } | ||
| } | ||
|
|
||
| public static void ex_5(int num) { | ||
|
|
||
| try { | ||
| ex_4(num); | ||
| } | ||
| catch (FileNotFoundException exception) { | ||
| System.out.println(1); | ||
| } | ||
| catch (BindException exception) { | ||
| System.out.println(2); | ||
| } | ||
| catch (AuthenticationException exception) { | ||
| System.out.println(3); | ||
| } | ||
| } | ||
|
|
||
| public static void ex_6(int num) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot to print "here", and try to solve it without saving a boolean |
||
| boolean bool = false; | ||
| try { | ||
| ex_4(num); | ||
| } | ||
| catch (FileNotFoundException exception) { | ||
| System.out.println(1); | ||
| bool = true; | ||
| } | ||
| catch (BindException exception) { | ||
| System.out.println(2); | ||
| bool = true; | ||
| } | ||
| catch (AuthenticationException exception) { | ||
| System.out.println(3); | ||
| bool = true; | ||
| } | ||
|
|
||
| if (bool == false) { | ||
| throw new RuntimeException(); | ||
| } | ||
| } | ||
| public static void ex_7() { | ||
| //להוריד את התנאי השני בפעולה הבונה כדי שיהיה שם | ||
| } | ||
|
|
||
| public static void ex_8() { | ||
| // להפוך את זה ל > במקום >= | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of making the exceptions' type Exception make it more specific