When in doubt, always check the source code. If you look at MenuItemCompat.java you'll find that it switches based on the API level like so:
static final MenuVersionImpl IMPL;
static {
final int version = android.os.Build.VERSION.SDK_INT;
if (version >= 14) {
IMPL = new IcsMenuVersionImpl();
} else if (version >= 11) {
IMPL = new HoneycombMenuVersionImpl();
} else {
IMPL = new BaseMenuVersionImpl();
}
}
The base setActionView method for the base implementation (which is used for 2.3 devices) just returns the MenuItem, so it wouldn't ever throw the exception:
@Override
public MenuItem setActionView(MenuItem item, View view) {
return item;
}
The HoneycombMenuVersionImpl, on the other hand, delegates to another class:
@Override
public boolean setShowAsAction(MenuItem item, int actionEnum) {
MenuItemCompatHoneycomb.setShowAsAction(item, actionEnum);
return true;
}
And the delegate class attempts to call the actual method on the MenuItem, which will throw an exception:
public static void setShowAsAction(MenuItem item, int actionEnum) {
item.setShowAsAction(actionEnum);
}
In this particular example, checking the source code answers your question and shows you a solid strategy for dealing with compatibility across different versions of Android.