Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added out/production/Exeptions/Main.class
Binary file not shown.
11 changes: 11 additions & 0 deletions src/Exeptions/Exeptions.iml
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>
113 changes: 113 additions & 0 deletions src/Exeptions/src/Main.java
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 {
Copy link

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


indexOutOfBoundsException.getStackTrace();
Copy link

Choose a reason for hiding this comment

The 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++) {
Copy link

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The 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() {
// להפוך את זה ל > במקום >=
}
}