LogRecord getThrown() method in Java with Examples
The getThrown() method of java.lang.reflect.LogRecord is used to get 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 Throwable getThrown()
Parameters: This method accepts nothing.
Return: This method returns a throwable.
Below programs illustrate getThrown() method:
Program 1:
// Java program to illustrate // getThrown() 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.INFO, "GFG Logger" ); logRecord.setThrown( new IOException( "Error in Input" )); // get Throwable object Throwable throwObj = logRecord.getThrown(); // print result System.out.println( "throwable object = " + throwObj .toString()); } } |
throwable object = java.io.IOException: Error in Input
Program 2:
// Java program to illustrate // getThrown() method 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.WARNING, "Logger" ); logRecord.setThrown( new ArithmeticException()); // get Throwable object Throwable throwObj = logRecord.getThrown(); // print result System.out.println( "throwable object = " + throwObj .toString()); } } |
throwable object = java.lang.ArithmeticException
References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/LogRecord.html#getThrown()
Recommended Posts:
- LogRecord getParameters() method in Java with Examples
- LogRecord getSequenceNumber() method in Java with Examples
- LogRecord getThreadID() method in Java with Examples
- LogRecord getInstant() method in Java with Examples
- LogRecord setSequenceNumber() method in Java with Examples
- LogRecord setResourceBundle() method in Java with Examples
- LogRecord getSourceMethodName() method in Java with Examples
- LogRecord setResourceBundleName() method in Java with Examples
- LogRecord getSourceClassName() method in Java with Examples
- LogRecord setInstant() method in Java with Examples
- LogRecord setMillis() method in Java with Examples
- LogRecord setThreadID() method in Java with Examples
- LogRecord getMillis() method in Java with Examples
- LogRecord getResourceBundleName() method in Java with Examples
- LogRecord getResourceBundle() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.