Created
September 11, 2016 11:48
-
-
Save ZhdanRuslan/77cbc8018ddaacc6dbe14f46b7decbba to your computer and use it in GitHub Desktop.
Level 38, Lesson 06, Home 01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.home01; | |
public enum ExceptionApplicationMessage { | |
UNHANDLED_EXCEPTION, | |
SOCKET_IS_CLOSED | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.home01; | |
public enum ExceptionDBMessage { | |
NOT_ENOUGH_CONNECTIONS, | |
RESULT_HAS_NOT_GOTTEN_BECAUSE_OF_TIMEOUT | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.home01; | |
/** | |
* Created by ruslan on 11.09.16. | |
*/ | |
public class ExceptionFactory | |
{ | |
public static Throwable getException(Enum enumeration) { | |
if (enumeration != null) { | |
String msg = enumeration.name().charAt(0) + enumeration.name().substring(1).toLowerCase().replace("_", " "); | |
if (enumeration instanceof ExceptionApplicationMessage) { | |
return new Exception(msg); | |
} | |
else if (enumeration instanceof ExceptionDBMessage) { | |
return new RuntimeException(msg); | |
} | |
else if (enumeration instanceof ExceptionUserMessage) { | |
return new Error(msg); | |
} | |
} | |
return new IllegalArgumentException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.home01; | |
public enum ExceptionUserMessage { | |
USER_DOES_NOT_EXIST, | |
USER_DOES_NOT_HAVE_PERMISSIONS | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.home01; | |
public class Solution { | |
public static Class getFactoryClass() { | |
return ExceptionFactory.class; | |
} | |
public static void main(String[] args) | |
{ | |
System.out.println(getFactoryClass()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment