The problem is this. In the class with the entry point there are try, catch blocks (this part of the code is shown below). I threw exceptions from other classes in catch and I would like to prologue each exception in a catch block. I looked at the documentation, screwed in the logger, but I don’t quite understand how to get each exception in one catch block in my case.
fileHandler= new FileHandler("Exceptions log.txt"); public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { try{ MailRepository mailRepository = new MailRepository(dbConnection); MailRepository dataModificator=new MailRepository(dbConnection); MailSender mailSender = new MailSender(dbConnection); List<Message> messageList = mailRepository.GetMessage(messageLimit); while(messageList.size() != 0){ messageList = mailRepository.GetMessage(messageLimit); for(int i=0; i<messageList.size();i++){ mailSender.send(messageList.get(i)); dataModificator.dataModification(Integer.parseInt(messageList.get(i).getId())); } } logger.addHandler(fileHandler); logger.setLevel(Level.ALL); logger.info("Start logging"); } catch(NumberFormatException |SQLException | NullPointerException | MessagingException e){ logger.log(Level.WARNING, "trouble sneezing", e); } logger.fine("Exception logged"); } };
NumberFormatException | SQLException | NullPointerException | MessagingException
:NumberFormatException | SQLException | NullPointerException | MessagingException
NumberFormatException | SQLException | NullPointerException | MessagingException
NumberFormatException | SQLException | NullPointerException | MessagingException
information will be displayed in the log, with a glass trace. AndLevel.WARNING
not particularly appropriate for exceptions, it’s still more appropriateLevel.ERROR
- iksuylog
method as a third parameter. - iksuytrouble sneezing
, but there is none. what is written to you linelogger.fine("Exception logged");
which is outside thecatch
block. Are you sure that your program enters the catch block? Check out the debugger. - iksuy