Last active
April 29, 2020 07:44
-
-
Save nicooga/dc99534a2be502fb577e507a534bf0c4 to your computer and use it in GitHub Desktop.
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
public enum PrinterExceptionReason { | |
NOT_ENOUGH_INK, | |
NO_PAPER, | |
PRINTER_NOT_CONNTECTED, | |
PRINTER_UNOPERATING | |
} | |
public class PrinterException extends Exception { | |
public int page; | |
public PrinterException(PrinterExceptionReason reason, int page) { | |
super(getMessage(reason)); | |
this.page = page | |
} | |
public PrinterException(String reason) { | |
super(getMessage(reason)); | |
} | |
static String getMessage(PrinterExceptionReason reason) { | |
switch (reason) { | |
case PrinterExceptionReason.NOT_ENOUGH_INK: | |
return 'Not enough ink'; | |
break; | |
// Los otros 3 casos ... | |
} | |
} | |
} | |
// ... | |
throw new PrinterException(PrinterExceptionReason.NO_PAPER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment