Skip to content

Instantly share code, notes, and snippets.

@nicooga
Last active April 29, 2020 07:44
Show Gist options
  • Save nicooga/dc99534a2be502fb577e507a534bf0c4 to your computer and use it in GitHub Desktop.
Save nicooga/dc99534a2be502fb577e507a534bf0c4 to your computer and use it in GitHub Desktop.
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