对于一个 android 库项目,我正在尝试创建一个强制关闭,以向该库的用户显示他忘记做某事。
为此,我尝试创建自定义异常以及throw
它们,但我只有 LogCat 中的一些警告,仅此而已。
前任:
我的活动.java
protected void onResume() {
super.onResume();
try {
this.isMenuButtonOk();
} catch(MyCustomException e) {
e.printStackTrace();
}
}
private void isMenuButtonOk() throws MyCustomException{
if(!this.mOnCreateOptionsMenuHasBeenCalledFlag)
throw new MyCustomException("OnCreateOptionMenu() needs to call it's parent. Or you need to deactivate the use of the menubutton");
}
日志猫
08-02 18:28:13.507 3866-3866/com.example.testlibrary W/System.err: com.example.testlibrary.MyCustomException: OnCreateOptionMenu() needs to call it's parent. Or you need to deactivate the use of the menubutton
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at com.example.testlibrary.lib.MyActivity.isMenuButtonOk(MyActivity.java:286)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at com.example.testlibrary.lib.MyActivity.onResume(MyActivity.java:244)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at com.example.testlibrary.MainActivity.onResume(MainActivity.java:304)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.Activity.performResume(Activity.java:5082)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.os.Looper.loop(Looper.java:137)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at android.app.ActivityThread.main(ActivityThread.java:4745)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at java.lang.reflect.Method.invoke(Method.java:511)
08-02 18:28:13.511 3866-3866/com.example.testlibrary W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-02 18:28:13.515 3866-3866/com.example.testlibrary W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-02 18:28:13.515 3866-3866/com.example.testlibrary W/System.err: at dalvik.system.NativeStart.main(Native Method)
您对发生此异常时如何模拟/创建此力关闭有任何想法吗?