Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

try..catch not working in Forte tutorial

0 views
Skip to first unread message

ryan

unread,
Aug 7, 2000, 3:00:00 AM8/7/00
to
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);
}
}

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

Markus Laun

unread,
Aug 8, 2000, 3:00:00 AM8/8/00
to
you might catch all exceptions then print them as
you might be getting a different exception to the one you
are trying to catch.

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);

Steve Chapel

unread,
Aug 8, 2000, 3:00:00 AM8/8/00
to
"ryan" <ryanbjor...@hotmail.com> wrote in message
news:398F220A...@hotmail.com...

> 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);
> }
> }
>
> 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)


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/


0 new messages