Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unhandled exception type ParseException [closed]

I'm using this part of code in my app :

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
Date qdate = new GregorianCalendar(0,0,0).getTime();
try {
    qdate = sdf.parse(dt);
} catch (ParseException e) {
    e.printStackTrace();
}

but Eclipse throws an error saying :

Unhandled exception type ParseException

What is the problem here? Do u need me to post the whole code ? Thnx in advance !

like image 703
Tasos Moustakas Avatar asked Jul 26 '12 08:07

Tasos Moustakas


People also ask

What is ParseException?

Class ParseExceptionSignals that an error has been reached unexpectedly while parsing. See Also: Exception , Format , FieldPosition , Serialized Form.

How do you get ParseException?

ParseException. Java uses text parsing to create an object based on a given String. If parsing causes an error, it throws a ParseException. Here, the String is malformed and causes a ParseException.

What is unhandled exception type?

An unhandled exception occurs when the application code does not properly handle exceptions. For example, When you try to open a file on disk, it is a common problem for the file to not exist. The . NET Framework will then throw a FileNotFoundException.

How do you handle Unparseable date exception in Java?

Basically, this exception occurs due to the input string is not correspond with the pattern. You can try the below format: SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.


1 Answers

See below code

        String date = "Sat, 23 Jun 2012 00:00:00 +0000";
        try {
            SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
            SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy");
            date = df2.format(date));
        } catch (java.text.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
like image 137
Nirali Avatar answered Nov 18 '22 05:11

Nirali