[code:1:2054a8c87f]
try {
if (sduration.length() > 2 ) {
String sd1 = sduration.substring(0, sduration.length()-2);
int intdur = Integer.parseInt(sd1);
if (intdur > 60) {
intdur = intdur / 60;
sd1 = String.valueOf(intdur);
remains = "hours left";
}
}
catch(Exception e) {
System.err.println("Oops! Something ugly happened...");
}
[/code:1:2054a8c87f]
I'm working on some j2me code and would like to trap math errors. When I tried to add a try/catch pair, it refuses to compile:
Building "Tank"
/home/jeff/wtk2.1/apps/Tank/src/Tank.java:84: 'catch' without 'try'
catch(Exception e) {
^
/home/jeff/wtk2.1/apps/Tank/src/Tank.java:71: 'try' without 'catch' or 'finally'
try {
^
2 errors
com.sun.kvem.ktools.ExecutionException
Build failed
Besides the compile error, am I going about this the right way? I think I'm getting bit when this app generates unacceptable math calculations:
When I feed it input that I know will crash it I get :
Running with storage root DefaultColorPhone
java.lang.NumberFormatException: 58.
at java.lang.Integer.parseInt(+210)
at java.lang.Integer.parseInt(+6)
at Tank.commandAction(+142)
at avax.microedition.lcdui.Display$DisplayAccessor.commandAction(+284)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)