Reputation: 6676
I am getting a NumberFormatException in my Logcat output and I would like to supress it. Apparently this exception only happens on Huawei devices (which I happen to own). For some reason my catch() block isn't executing. Can somebody please help:
Specifically, I would like to know why my catch() code is not called.
Locale locale = Locale.getDefault();
System.out.println("Locale is : [" + locale + "]"); // make sure there is a default Locale
System.out.printf( "==Before try{}\n" );
try
{
System.out.printf( "---Line44\n" );
Calendar c = Calendar.getInstance(locale);
System.out.printf( "---Line46\n" );
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.printf( "---Line48\n" );
String formattedDate = df.format(c.getTime());
System.out.printf( "---Line50\n" );
System.out.printf( "Timestamp : %s\n", formattedDate );
System.out.printf( "---Line52\n" );
}
catch( java.lang.NumberFormatException e )
{
// Ignore stupid exception - Huawei specific apparently..
System.out.printf( "HUAWEI bug\n" );
}
System.out.printf( "==After Entire Block, Line60\n" );
For more information, the Huawei bug is mention here but surely there must be something wrong with my try/catch statement?
Here is the exception dump:
10-01 11:07:53.402: I/System.out(1758): ==Before try{}
10-01 11:07:53.402: I/System.out(1758): ---Line44
10-01 11:07:53.432: W/System.err(1758): java.lang.NumberFormatException: Invalid int: ""
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.invalidInt(Integer.java:138)
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.parseInt(Integer.java:359)
10-01 11:07:53.432: W/System.err(1758): at java.lang.Integer.parseInt(Integer.java:332)
10-01 11:07:53.432: W/System.err(1758): at java.util.Calendar.getHwFirstDayOfWeek(Calendar.java:807)
10-01 11:07:53.432: W/System.err(1758): at java.util.Calendar.<init>(Calendar.java:745)
10-01 11:07:53.432: W/System.err(1758): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:338)
10-01 11:07:53.442: W/System.err(1758): at java.util.GregorianCalendar.<init>(GregorianCalendar.java:314)
10-01 11:07:53.442: W/System.err(1758): at java.util.Calendar.getInstance(Calendar.java:1098)
10-01 11:07:53.442: W/System.err(1758): at com.example.test.MyApplication.onCreate(MyApplication.java:45)
10-01 11:07:53.442: W/System.err(1758): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3954)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.access$1300(ActivityThread.java:123)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
10-01 11:07:53.442: W/System.err(1758): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 11:07:53.442: W/System.err(1758): at android.os.Looper.loop(Looper.java:137)
10-01 11:07:53.442: W/System.err(1758): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-01 11:07:53.442: W/System.err(1758): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 11:07:53.442: W/System.err(1758): at java.lang.reflect.Method.invoke(Method.java:511)
10-01 11:07:53.442: W/System.err(1758): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
10-01 11:07:53.442: W/System.err(1758): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
10-01 11:07:53.442: W/System.err(1758): at dalvik.system.NativeStart.main(Native Method)
10-01 11:07:53.442: I/System.out(1758): ---Line46
10-01 11:07:53.452: I/System.out(1758): ---Line48
10-01 11:07:53.462: I/System.out(1758): ---Line50
10-01 11:07:53.462: I/System.out(1758): Timestamp : 2014-10-01 11:07:53
10-01 11:07:53.462: I/System.out(1758): ---Line52
10-01 11:07:53.462: I/System.out(1758): ==After Entire Block, Line61
Upvotes: 0
Views: 635
Reputation: 2143
I would check the source for the other items in the call stack. seems like it might be possible that something else is catching and logging and returning without the exception to your code. does the timestamp line show up in the output?
Upvotes: 2