Pages

Wednesday, October 3, 2012

Using third party library and how to handle exceptions?

I think most of you must have come across situations where you need to use third party classes and you need to do some changes. Sometimes you can do this by decompiling the .class file then modifying it. The point is it works some times. But not always. Specially when the code is  obfuscated, chances are very low of decompilling correctly. So how can you overcome this? Well the most suitable method to do this is to use a wrapper class that extends the third party class.

Eg;
///this is the third party class
public class SomeLibrary{
     public void readBook(){

     }
}


Now you can write the wrapper class like this.


public class MyLibrary extends SomeLibrary{

        public void readBook(){

              try{
                     super.readBook() 
              }catch(Exception e){
                  //// catch the exception.
              }
       }
}

No comments:

Post a Comment