| Reply | « Previous Thread | Next Thread » |
|
Hello,
In the midlet I've done, when it sends a SMS to a invalid phonenumber (i.e, 111222), there is a system error alert that says "Message sending failed". I am wondering if I can monitor this alert, because when it appears, I can't control the display that is visible, so the user can navigate correctly through the application. I am controlling this exceptions try { smsconn.send(sms); } atch (Exception exception) { if (exception instanceof SecurityException) { /* do something */ } if (exception instanceof IOException) { /* do something */ } if (exception instanceof IllegalArgumentException) { /* do something */ } if (exception instanceof InterruptedIOException) { /* do something */ } if (exception instanceof NullPointerException) { /* do something */ } } but the midlet does another thing. Any guess about what I am missing? Regards |
|
its the exception syntax that is a bit weird. try it the standard way:
try { smsconn.send(sms); } catch(SeurityException secex) { /* do something */ } catch(IOException ioex) { /* do something */ } catch(IllegalArgumentException iargex) { /* do something */ } catch(InterruptedIOException iioex) { /* do something */ } catch(NullPointerException nex) { /* do something */ } catch (Exception ex) { // do something here } finally{ // ne exceptions until here // do something anyway } note: the order in which you catch the excteption is important. special exceptions first, generic exceptions last. errors are not catchable (memory error). but such sms-sending failed system errors should cause exceptions. thing is what exception is thrown. in the catch(Exception ex) you may print the exception to screen and see which one you got. good luck :) |
|
According to the specification for send(), you are catching everything that it can throw.
Remember that a catch() clause will match an exception of the specified type, or an exception of any subclass of the specified type. So there is no point catching IOException, then later trying to catch InterruptedIOException, as InterruptedIOException is a subclass of IOException. For example: Code:
try {
throw new InterruptedIOException ();
}
catch (IOException e) {
// the exception will get caught here, because
// InterruptedIOException is a subclass of IOException
}
catch (InterruptedIOException e) {
// this is unreachable
}
Code:
try {
throw new InterruptedIOException ();
}
catch (Exception e) {
// any subclass of Exception will get caught here
if (e instanceof {
// an InterruptedIOException is an instance of
// IOException, so this code gets executed
}
if (e instanceof InterruptedIOException) {
// because there is no "else", this gets executed too!
// if it was written "else if" then this would be
// unreachable
}
}
Code:
try {
// do stuff here
}
catch (Throwable t) {
// if anything is thrown, you will catch it here
}
Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|