Skip to content
Open
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
36 changes: 29 additions & 7 deletions src/main/java/org/future/code/homework/HomeWork3.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,37 @@ public class HomeWork3 {
* для ExportException вернуть строку "ExportException"
*/

public static void raiseException(Integer exceptionId) throws Exception { // Подсказка: throws Exception в итоге надо поменять на перечисление имен исключений
// Напиши свой код тут для задания 1
throw new Exception();
public static void raiseException(Integer exceptionId) throws Exception {
if (exceptionId == 1) {
throw new SocketException();
}
if (exceptionId == 2){
throw new ClassNotFoundException();
}
if (exceptionId == 3) {
throw new AccessDeniedException("");
}
if (exceptionId == 4) {
throw new ExportException("");
}
}

public static String catchException(Integer integer) {
// Напиши свой код тут для задания 2


public static String catchException(Integer integer){
try {
raiseException(integer);
} catch (SocketException e) {
return "SocketException";
} catch(ClassNotFoundException e) {
return "ClassNotFoundException";
} catch (AccessDeniedException e) {
return "AccessDeniedException";
} catch (ExportException e) {
return "ExportException";
}
return "Exception";
}


public static void main(String[] args) {
testFirstTask();
Expand Down Expand Up @@ -133,4 +155,4 @@ public static void printTestCase(int n, String exp, String act, int minLen) {
System.out.println();
}

}
}