Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:30:03+00:00 2026-06-05T10:30:03+00:00

I’m new to java and trying to learn how to log an exception by

  • 0

I’m new to java and trying to learn how to log an exception by example. I found the following example code here:

http://www.kodejava.org/examples/447.html

However, I don’t see where the filename for the log file is specified. When I research the question on Google usually people refer to the framework used for programming java to figure out where the log file gets stored. However, I’m not using a framework. I’m just creating my java files using VIM editor from the command line. The java file sits on an Linux CentOS application server and is called from a client’s browser.

Question 1: Is it possible to modify the example below to include a file name and path for logging? Or, am I way off base with this question?

Question 2: Even though I log the exception, will it still propagate to the client for the user to view? Hopefully it will, otherwise the user won’t know an error has occurred.

package org.kodejava.example.util.logging;

import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;

public class LoggingException {
private static Logger logger = Logger.getLogger(LoggingException.class.getName());

public static void main(String[] args) {
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setLenient(false);

    try {
        //
        // Try to parsing a wrong date.
        //
        Date date = df.parse("12/30/1990");

        System.out.println("Date = " + date);
    } catch (ParseException e) {
        //
        // Create a Level.SEVERE logging message
        //
        if (logger.isLoggable(Level.SEVERE)) {
            logger.log(Level.SEVERE, "Error parsing date", e);
        }
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:30:04+00:00Added an answer on June 5, 2026 at 10:30 am

    Try this:

    try {
        FileHandler handler = new FileHandler("myLogFile.log", true);
        Logger logger = Logger.getLogger(LoggingException.class.getName());
        logger.addHandler(handler);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Error parsing date", e);
    }
    

    By default, a file handler overwrites the contents of the log file each time it is created. You might also want to append log file so in FileHandler constructor you need to specify true as a second parameter.

    Hope this helps.

    EDIT:

    package org.kodejava.example.util.logging;
    
    import java.util.logging.Logger;
    import java.util.logging.Level;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    
    public class LoggingException {
    private static Logger logger = Logger.getLogger(LoggingException.class.getName());
    
    public static void main(String[] args) {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        df.setLenient(false);
        FileHandler handler = new FileHandler("myLogFile.log", true);
        logger.addHandler(handler);
        try {
            //
            // Try to parsing a wrong date.
            //
            Date date = df.parse("12/30/1990");
    
            System.out.println("Date = " + date);
        } catch (ParseException e) {
            //
            // Create a Level.SEVERE logging message
            //
            if (logger.isLoggable(Level.SEVERE)) {
                logger.log(Level.SEVERE, "Error parsing date", e);
            }
        }
      }
    }
    

    This should work. I did not test it.
    More efficient way would be create a method to initialize logger and add handler to it. But I will mostly recommend you to think about using log4j. It is easy to set up and widely used logging framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.