LogRecord setThrown() method in Java with Examples Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The setThrown() method of java.util.logging.LogRecord is used to a throwable associated with the log event.This is used to log Exceptions in the logRecord that can be used for logging messages. Syntax: public void setThrown(Throwable thrown) Parameters: This method accepts thrown as a parameter which is a throwable object. It can be null also. Return: This method returns nothing. Below programs illustrate setThrown() method: Program 1: Java // Java program to illustrate setThrown() method import java.io.IOException; import java.util.logging.Level; import java.util.logging.LogRecord; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord(Level.SEVERE, "Hello Logger"); // set throwable object logRecord.setThrown( new IOException( "Error in Input")); // print the method name System.out.println( "throwable object Message = " + logRecord.getThrown() .toString()); } } Output: throwable object Message = java.io.IOException: Error in Input Program 2: Java // Java program to illustrate setThrown() method import java.io.IOException; import java.util.logging.Level; import java.util.logging.LogRecord; public class GFG { public static void main(String[] args) { // Create LogRecord object LogRecord logRecord = new LogRecord(Level.SEVERE, "Hello Logger"); // create a throwable object Exception exception = new ArithmeticException( "divide by 0"); // set throwable object logRecord.setThrown(exception); // print the result System.out.println( "throwable object = " + logRecord.getThrown() .toString()); } } Output: throwable object = java.lang.ArithmeticException: divide by 0 References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#setThrown(java.lang.Throwable) Comment More infoAdvertise with us Next Article LogRecord setThrown() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-LogRecord java.util.logging package Practice Tags : Java Similar Reads LogRecord setThreadID() method in Java with Examples The setThreadID() method of java.util.logging.LogRecord is used to set an identifier for the thread where the message originated. This method is helpful to identify thread which generates the logger message. Syntax: public void setThreadID(int threadID) Parameters: This method accepts threadID which 2 min read LogRecord setInstant() method in Java with Examples The setInstant() method of java.lang.reflect.LogRecord is used to set this instant that the event occurred this is helpful to record logging events instant. An arithmeticException will be thrown if the given instant represents a point on the timeline too far in the future or past to fit in long mill 2 min read Logger throwing() method in Java with Examples throwing(String sourceClass, String sourceMethod, Throwable thrown) method is used to Log throwing an exception.In many scenario method is closed by throwing an exception then this is a very helpful method to log that a method is terminating by throwing an exception. The logging is done using the FI 2 min read LogRecord setParameters() method in Java with Examples The setParameters() method of java.util.logging.LogRecord is used to set the parameters to the log message.These parameters are the parameters to be inserted into the message of this LogRecord. Syntax: public void setParameters(Object[] parameters) Parameters: This method accepts parameters as param 2 min read LogRecord setLoggerName() method in Java with Examples The setLoggerName() method of java.util.logging.LogRecord is used to set the logger name of source.This method returns source logger name if present else returns null. Syntax: public void setLoggerName(String name) Parameters: This method accepts the Source Logger name as a string which can be null 1 min read Like