title: How does one catch an exception thrown by the main method in java?
body: <pre><code>public static void main(String[] args) throws IllegalArgumentException {
    if (args[0].matches(".*\\w.*")) {
      throw new IllegalArgumentException("Can't input characters!");
    }
    String input = insertSpaces(args[0]);
    args = input.split("\\s+");
    printAnswer(calculate(args),args);
  } 
  </code></pre>
  
  <p>In the above code, the main method throws an IllegalArgumentException. How do I catch the exception thrown from the main method? The reason I ask, and if I'm incorrect please correct me, is because my understanding is that when a method throws an exception, the caller of the method is responsible for catching the exception. The main method in this case has no other method calling it so I can't figure out how to catch the exception. I'm guessing the JVM is working behind the scenes to call the method but then how would I make the JVM catch the execption. Please provide CODE if possible along with explanation. Otherwise explain why not possible.</p>