Skip to content

Instantly share code, notes, and snippets.

@ZhdanRuslan
Created September 11, 2016 11:48
Show Gist options
  • Save ZhdanRuslan/77cbc8018ddaacc6dbe14f46b7decbba to your computer and use it in GitHub Desktop.
Save ZhdanRuslan/77cbc8018ddaacc6dbe14f46b7decbba to your computer and use it in GitHub Desktop.
Level 38, Lesson 06, Home 01
package com.javarush.test.level38.lesson06.home01;
public enum ExceptionApplicationMessage {
UNHANDLED_EXCEPTION,
SOCKET_IS_CLOSED
}
package com.javarush.test.level38.lesson06.home01;
public enum ExceptionDBMessage {
NOT_ENOUGH_CONNECTIONS,
RESULT_HAS_NOT_GOTTEN_BECAUSE_OF_TIMEOUT
}
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();
}
}
package com.javarush.test.level38.lesson06.home01;
public enum ExceptionUserMessage {
USER_DOES_NOT_EXIST,
USER_DOES_NOT_HAVE_PERMISSIONS
}
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