Logger throwing() method in Java with Examples Last Updated : 28 Mar, 2019 Comments Improve Suggest changes Like Article Like Report 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 FINER level logging. If the level of the logger is set to log FINER level logging then the given arguments are stored in a log record with a message THROW which is forwarded to all registered output handlers. Syntax: public void throwing(String sourceClass, String sourceMethod, Throwable thrown) Parameters: This method accepts three parameters: sourceClass is the name of the class that issued the logging request, sourceMethod is the name of the method and result is The Throwable that is being thrown. Return value: This method returns nothing. Below programs illustrate throwing(String sourceClass, String sourceMethod, Object result) method: Program 1: Java // Java program to demonstrate // throwing(String, String, Throwable) method import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; public class GFG { public static void main(String[] args) throws SecurityException, IOException { // Create a Logger Logger logger = Logger.getLogger( GFG.class.getName()); // Create a file handler object FileHandler handler = new FileHandler("logs.txt"); handler.setFormatter(new SimpleFormatter()); // Add file handler as // handler of logs logger.addHandler(handler); // set Logger level() logger.setLevel(Level.FINER); // set Logger level() logger.setLevel(Level.FINER); // call throwing method with class // name = GFG and method name = main // and IO Exception as Thrown object logger.throwing(GFG.class.getName(), GFG.class.getMethods()[0].getName(), new IOException()); } } The output printed on log.txt is shown below. Output: Program 2: Java // Java program to demonstrate // throwing(String, String, Throwable) method import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; public class GFG { // Create a Logger static Logger logger = Logger.getLogger( GFG.class.getName()); public static void main(String[] args) throws SecurityException, IOException { // Create a file handler object FileHandler handler = new FileHandler("logs.txt"); // Add file handler as // handler of logs logger.addHandler(handler); // set Logger level() logger.setLevel(Level.FINER); // set Logger level() logger.setLevel(Level.FINER); // call throwing method with string // and ArithmeticException as Thrown object logger.throwing(String.class.getName(), String.class.getMethods()[0].getName(), new ArithmeticException()); } } The output printed on log.txt is shown below. Output: Reference: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Logger.html#throwing(java.lang.String, java.lang.String, java.lang.Throwable) Comment More infoAdvertise with us Next Article Logger throwing() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-Logger Practice Tags : Java Similar Reads Logger warning() method in Java with Examples The warning() method of a Logger class used to Log a WARNING message.This method is used to pass WARNING types logs to all the registered output Handler objects. WARNING Message: Warning may occur whenever the user has given wrong input or credentials. There are two types of warning() method dependi 2 min read LogRecord setThrown() method in Java with Examples 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 whic 2 min read Logger severe() method in Java with Examples The severe() method of a Logger class used to Log a SEVERE message.This method is used to pass SEVERE types logs to all the registered output Handler objects. SEVERE Message: Severe occurs when something terrible has occurred and the application cannot continue further. Ex like database unavailable, 2 min read Logger setFilter() method in Java with Examples setFilter() method of a Logger class is used to set a filter to control output on this Logger. The filter is passed as a parameter. A Filter is useful to filter out log messages. It can be said that the filter decides the message gets to be logged or not. Filters are represented by the Java interfac 2 min read Logger log() Method in Java with Examples The log() method of Logger is used to Log a message. If the logger is currently enabled for the given message level which is passed as parameter then a corresponding LogRecord is created and forwarded to all the registered Output Handler objects. But in logger class, there are seven different log() 6 min read Like