Skip to main content

?? Will MIDletStateChangeException affects Midlet's performance ??

4 replies [Last post]
dextml
Offline
Joined: 2007-09-19
Points: 0

i'm writing a j2me game.
There is a MIDletStateException that can be appended right after the startApp and destroyApp.

i wonder if this optional exception throwing clause can slow down the app a bit?
And,..
By adding the exception handler, how much extra work would be involved???

Any form of help would be greatly appreciated.
ty
DeXtmL

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Putting an exception thrown notation on a method does not do anything to hinder the performance.
Additionally the try/catch block that has to encompass the method or constructor takes no extra processing, UNLESS the exception is thrown.

The exception notation and subsequent try/catch do require more resources for the exception catching, exception definitions, and wrapping code. However this can be offset by the removal of things like if( arrayX != null && arrayX.length > 0) and just have a nullpointer exception and an arrayoutofbounds exception being caught. This makes since when the case for arrayX being null or having no elements is >1% of the time.

-Shawn

dextml
Offline
Joined: 2007-09-19
Points: 0

Very helpful. thanks alot.
the question has just one notch from being answered: i can feel free to add try/catch blocks into my app?
i do not precisely understand your words "exception notation".

my understanding is like this:

try{
someMethodsThatWouldThrowExceptions(); // no performance hit
}
catch(Exception e) {
handleException(); // low performance here
}

DeXmtL

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Sorry, should have explained that a bit. Try/catch is what you put around the method call that throws the exception. The "exception notation" is what is placed on the method call to inform the Java compiler to require the try/catch be used. (It's my term not an industry standard)

So you have method "foo" that throws an exception:
public void foo( ) throws NullPointerException <<--- exception notation
{ /* do something here */ }

private void bar()
{ try { foo() } catch(NullPointerException npe) { /* handle exception */} }

Hope that clarifies my suggestion.
-Shawn

dextml
Offline
Joined: 2007-09-19
Points: 0

Millions of thx.
Nice to see this issue is solved