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 A AmanSingh2210 Follow Improve Article Tags : Java Java-Exceptions Java-lang package Java-Exception Handling Java-Functions java-Throwable +2 More Practice Tags : Java Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like