• smali 语法之try catch语句


    # virtual methods
    .method public onClick(Landroid/view/View;)V
        .locals 4
        .parameter "v"
    
        .prologue
        .line 62
        :try_start_0
        const-string v3, "try 1"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_0
        .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_2
    
        .line 64
        :try_start_1
        const-string v3, "try 2"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_1
        .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1
    
        .line 66
        :try_start_2
        const-string v3, "try 3"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
    
        .line 67
        const-string v3, "continue3"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_2
        .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_0
    
        .line 71
        :goto_0
        :try_start_3
        const-string v3, "continue2"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_3
        .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_1
    
        .line 75
        :goto_1
        :try_start_4
        const-string v3, "continue1"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_4
        .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_4} :catch_2
    
        .line 79
        :goto_2
        return-void
    
        .line 68
        :catch_0
        move-exception v2
    
        .line 69
        .local v2, e3:Ljava/lang/Exception;
        :try_start_5
        const-string v3, "e3"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_5
        .catch Ljava/lang/Exception; {:try_start_5 .. :try_end_5} :catch_1
    
        goto :goto_0
    
        .line 72
        .end local v2           #e3:Ljava/lang/Exception;
        :catch_1
        move-exception v1
    
        .line 73
        .local v1, e2:Ljava/lang/Exception;
        :try_start_6
        const-string v3, "e2"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
        :try_end_6
        .catch Ljava/lang/Exception; {:try_start_6 .. :try_end_6} :catch_2
    
        goto :goto_1
    
        .line 76
        .end local v1           #e2:Ljava/lang/Exception;
        :catch_2
        move-exception v0
    
        .line 77
        .local v0, e1:Ljava/lang/Exception;
        const-string v3, "e1"
    
        invoke-static {v3}, Ljava/lang/System;->clearProperty(Ljava/lang/String;)Ljava/lang/String;
    
        goto :goto_2
    .end method
            顺序分析:
                try {                                    //try0
                    System.clearProperty("try 1");
                } catch                                 //catch_2
                
                try {                                    //try1
                    System.clearProperty("try 1");
                } catch                                 //catch_1
                
                
                try {                                    //try2
                    System.clearProperty("try 3");
                    System.clearProperty("continue3");
                } catch                                 //catch_0
    
                //:goto 0
                try {                                    //try3
                    System.clearProperty("continue2");
                } catch                                 //catch_1
                    
                //:goto 1
                try {                                    //try4
                    System.clearProperty("continue1");
                } catch                                 //catch_2
                
                //:goto_2
                return-void                                //唯一出口,void类型
                
                //:catch_0
                Exception e3 {                
                    System.clearProperty("e3");
                }
                //goto :goto_0
                
                //:catch_1
                Exception e2 {                    
                    System.clearProperty("e2");
                }
                //goto :goto_1
                
                //:catch_2
                Exception e1 {                    
                    System.clearProperty("e1");            
                }
                //goto :goto_2
                
            变形:
                try {                                    //try1
                    System.clearProperty("try 1");
                //:goto 1    
                    try{                    
                    System.clearProperty("continue1");    //try4
                    }
                } catch(Exception e1)                     //catch_2合并
                {                    
                    System.clearProperty("e1");            
                }
                //goto :goto_2
                
                
                try {                                    //try0
                    System.clearProperty("try 2");
                //:goto 0
                    try{                    
                    System.clearProperty("continue2");    //try3
                    }
                } catch(Exception e2)                     //catch_1合并
                {                    
                    System.clearProperty("e2");            
                }
                //goto :goto_1
                
                
                try {                                    //try2
                    System.clearProperty("try 3");
                    System.clearProperty("continue3");
                } catch(Exception e3) {                    //catch_0
                    System.clearProperty("e3");
                }
                //goto :goto_0    
                
                //:goto_2
                return-void                                //唯一出口,void类型
                
            处理goto,合并try
                try {
                    System.clearProperty("try 1");
                    try {
                        System.clearProperty("try 2");
                        try {
                            System.clearProperty("try 3");
                            System.clearProperty("continue3");
                        } catch (Exception e3) {
                            System.clearProperty("e3");
                        }
                        System.clearProperty("continue2");
                    } catch (Exception e) {
                        System.clearProperty("e2");
                    }
                    System.clearProperty("continue1");
                } catch (Exception e) {
                    System.clearProperty("e1");
                }
                
                
            goto小技巧:先处理小的,比如:goto0----goto1---goto2---......
  • 相关阅读:
    Java 位运算(移位、位与、或、异或、非)
    解决Android Studio 2.2.3中添加.cpp .h文件在Project->Android无法显示,无法正常编译问题。
    [ACM] HDU 5083 Instruction (模拟)
    Vbox视图热键
    Android Drawable 与 LayerList综合汇总
    数学之路-python计算实战(14)-机器视觉-图像增强(直方图均衡化)
    HDU 2896 病毒侵袭 AC自己主动机题解
    对团队中“这是某某某的问题”引起的思考
    杭电 2201
    三层架构
  • 原文地址:https://www.cnblogs.com/shuoshuo/p/3443879.html
Copyright © 2020-2023  润新知