Debugging in Java – Setting a debugMode flag

Debugging in Java – Setting a debugMode flag

Apologies for a noobish question.

I am developing a JavaFX application.

I want to set a ‘Global’ boolean type variable ‘DebugMode’, Such that when a custom(I mean customized, or made by myself) exception is thrown, the getMessage() function can check the DebugMode variable to see if the DebugMode is set.

If DebugMode is ‘true’, then the exception can give detailed message for debugging, Or else just user friendly messages for the end users.

Is it possible in java, just like $GLOBAL variable in PHP? Or is there any alternative way for giving two different exception messages for developer and end user?

Go for -D argument (JVM Properties). This means, that when I start the application from command-line. I can do something like,

     java Hello -DdetailedDebugMode=true

And in the java code I can do something like:

  printError(Throwable t) {
      if(System.getProperties("detailedDebugMode") != null && "true".equalsIgnoreCase(System.getProperties("detailedDebugMode"))) {
          LOG.error("Here is the message", e);
      } else {
          LOG.error("Here is the message only");
      }
  }
.
.
.
.