-2

I want to manage my exceptions like this :

protected String displayException(Exception e, String specificMessage) {
        String message = (specificMessage == null) ? e.getMessage() : specificString;
        return message;
    }

Do I have an annotation that would allow me to do so (example @Nullable or @Optional)? And if yes, in which library can I find it (example @Nullable is in the Spring library and in the Jetbrains library)

Guillaume Gaujac
  • 1,661
  • 2
  • 7
  • 8
  • 1
    In Java single way is using method overloading. protected String displayException(String specificMessage){displayException(null,specificMessage);} – KreminT Nov 13 '20 at 17:02

1 Answers1

1

You can overload your method:

protected String displayException(Exception e) {
    return displayException(e, null)
}
Jens
  • 67,715
  • 15
  • 98
  • 113