Throwable getMessage() method in Java with Examples Last Updated : 06 Feb, 2019 Comments Improve Suggest changes Like Article Like Report The getMessage() method of Throwable class is used to return a detailed message of the Throwable object which can also be null. One can use this method to get the detail message of exception as a string value. Syntax: public String getMessage() Return Value: This method returns the detailed message of this Throwable instance. Below programs demonstrate the getMessage() method of java.lang.Throwable Class Example 1: Java // Java program to demonstrate // the getMessage() Method. import java.io.*; class GFG { // Main Method public static void main(String[] args) throws Exception { try { // divide the numbers divide(2, 0); } catch (ArithmeticException e) { System.out.println("Message String = " + e.getMessage()); } } // method which divide two numbers public static void divide(int a, int b) throws ArithmeticException { int c = a / b; System.out.println("Result:" + c); } } Output: Message String = / by zero Example 2: Java // Java program to demonstrate // the getMessage() Method. import java.io.*; class GFG { // Main Method public static void main(String[] args) throws Exception { try { test(); } catch (Throwable e) { System.out.println("Message of Exception : " + e.getMessage()); } } // method which throws UnsupportedOperationException public static void test() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } } Output: Message of Exception : null References: https://docs.oracle.com/javase/10/docs/api/java/lang/Throwable.html#getMessage() Comment More infoAdvertise with us Next Article Throwable getMessage() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Exceptions Java-lang package Java-Exception Handling Java-Functions java-Throwable +2 More Practice Tags : Java Similar Reads Throwable getLocalizedMessage() method in Java with Examples The getLocalizedMessage() method of Throwable class is used to get a locale-specific description of the Throwable object when an Exception Occurred. It helps us to modify the description of the Throwable object according to the local Specific message. For the subclasses which do not override this me 2 min read Throwable getCause() method in Java with Examples The getCause() method of Throwable class is the inbuilt method used to return the cause of this throwable or null if cause can't be determined for the Exception occurred. This method help to get the cause that was supplied by one of the constructors or that was set after creation with the initCause( 2 min read Throwable getSuppressed() method in Java with Examples The getSuppressed() method of Throwable class used to return an array containing all of the exceptions that were suppressed to deliver this exception typically this suppression done by the try-with-resources statement. In order to deliver Exception If no exceptions were suppressed or suppression is 2 min read LogRecord getMessage() method in Java with Examples The getMessage() method of java.util.logging.LogRecord is used to get the actual log message, before localization or formatting from this logRecord.This message may be null, which is equivalent to the empty string "". This returned message may be either the final text or a localization key. Syntax: 2 min read Optional get() method in Java with examples The get() method of java.util.Optional class in Java is used to get the value of this Optional instance. If there is no value present in this Optional instance, then this method throws NullPointerException. Syntax: public T get() Parameters: This method do not accept any parameter. Return value: Thi 2 min read Like