Mistři v programování na #hovnokod

Java #987

Na co všecko se dá použít obyčejná výjimka a její text.

private static final String TRUNCATION_ERROR = "Error during payment processing: Truncation is not allowed";

private void truncateToSize(...) throws Exception {
   ...
   if (...) throw new Exception(TRUNCATION_ERROR);
   ...
}

public void considerFieldsTruncationToMaxSize() {
   try {
      ...
      truncateToSize(...);
      ...
   } catch (Exception ex) {
      if(TRUNCATION_ERROR.equals(ex.getMessage())) {
         reportError(TRUNCATION_ERROR);
      } else {
         throw new Exception(TRUNCATION_ERROR);
      }
   }
}

Anonymous,