2

Me and my colleagues are currently working on a Java project. When in need of throwing an Exception for whatever reason, some of them will throw a standard Exception

        if ( !pduForConversion.isPresent())
        throw new Exception("Pdu optional is empty from get with oid "+oidForConversion.toString());

Another approach is to extend Exception and give it a custom name

    class emptyPduException extends Exception {
    public emptyPduException(String message) {
        super(message);
    }
}

      if (!getPduResponse.isPresent())
        throw new emptyPduException("Pdu optional is empty from get with oid " + convertedOid);

Which approach is considered more consistent? Are they equivalent?

Pierangelo Calanna
  • 572
  • 1
  • 3
  • 17

0 Answers0