private void jbtnNewTimeFormatMouseClicked (java.awt.event.MouseEvent
evt) {
try {
String timeFormat = jtfNewTimeFormat.getText();
formatter = new SimpleDateFormat(timeFormat);
} catch (java.lang.IllegalArgumentException i) {
JOptionPane.showMessageDialog(this,
"Invalid time format",
"I don't understand your time format.",
JOptionPane.ERROR_MESSAGE);
}
}
If I give it 'EEEE' (day of week) no problem, but if I do 'eeee', I get:
java.lang.IllegalArgumentException: Illegal pattern character 't'
at
java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:477)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:437)
at java.text.DateFormat.format(DateFormat.java:305)
at ClockFrame.ClockFrame.tmrSecondsOnTime(ClockFrame.java:143)
at ClockFrame.ClockFrame.access$0(ClockFrame.java:140)
at ClockFrame.ClockFrame$1.onTime(ClockFrame.java:46)
at
org.netbeans.examples.lib.timerbean.Timer.fireTimerEvent(Timer.java:133)
at
org.netbeans.examples.lib.timerbean.Timer.access$1(Timer.java:124)
at
org.netbeans.examples.lib.timerbean.Timer$TimerThread.run(Timer.java:144)
this comes when I call SimpleDateFormat. So I added the catch, but it's
no catching it. Any ideas? Even if something in SimpleDateFormat is
causing the exception, the catch should still work, right?
Thanks,
Ryan
ryan wrote:
>
> In the Forte clock tutorial, I am trying to add a try .. catch for
> illegal time format. This is not part of the tutorial, but I thought I
> would try it.
>
> private void jbtnNewTimeFormatMouseClicked (java.awt.event.MouseEvent
> evt) {
> try {
> String timeFormat = jtfNewTimeFormat.getText();
> formatter = new SimpleDateFormat(timeFormat);
> } catch (java.lang.IllegalArgumentException i) {
> JOptionPane.showMessageDialog(this,
> "Invalid time format",
> "I don't understand your time format.",
> JOptionPane.ERROR_MESSAGE);
> }
catch(Exception ex){
System.err.println("got unexpected Exception: "+ex);
I can't help but notice that the exception's stack trace doesn't include the
method that you posted (jbtnNewTimeFormatMouseClicked). Apparently, the
exception is occurring in some other place in your code, so of course the
catch block you show is never reached.
--
Java Programmers FAQ: http://www.afu.com/javafaq.html
Java Docs: http://java.sun.com/docs/