title: super class constructor in custom exception in java
body: <p>I am learning features in java including exceptions. I am writing a custom exceptions. Here is what i am doing :custom exception class:</p>
  
  <pre><code> public class ServiceException extends Exception {
  
      private String customMessage;
  
      public ServiceException(String customMessage) {
          super(customMessage);
          this.customMessage = customMessage;
  
      }
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>    public class Main {
  
      public static void main(String[] args) {
          try {
              new Main().test();
          } catch (Exception e) {
              System.out.println("the exception message is " + e.getMessage());
          }
      }
  
      public void test() throws ServiceException {
          try {
              int i = 1 / 0;
          } catch (Exception e) {
              throw new ServiceException(e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>This much i know:
  if super class constructor  is not invoked in the custom exception class, the message set in the custom exception is not passed to the Exception class. But if i have a method <strong>public String getMessage</strong> in my custom exception class, even if the super is not invoked, that message is printed . Sorry  if this is a naive question. But i am failing to understand he concept. Could come one help clear the concept ?</p>