March 2018
Intermediate to advanced
324 pages
8h 30m
English
Let's do a simple if and throw a RuntimeException when the result is not expected:
private void setBox(TicTacToeBean bean) {
if (board[bean.getX() - 1][bean.getY() - 1] != '\0') {
throw new RuntimeException("Box is occupied");
} else {
board[bean.getX() - 1][bean.getY() - 1] = lastPlayer;
// getTicTacToeCollection().saveMove(bean);
if (!getTicTacToeCollection().saveMove(bean)) {
throw new RuntimeException("Saving to DB failed");
}
}
}
Read now
Unlock full access