Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obfuscating method with throws clause

I'm using ProGuard to obfuscate my code. My project is comprised of a few modules, each obfuscated independently.

One library includes an interface;

public interface IFace {
    public int methodA(boolean b) throws CustomException;
}

Another library provides an implmentation

public class IFaceImpl implements IFace {
    @Override
    public int methodA(boolean b) throws CustomException {
        return 0;
    }
}

The library with the interface is built first, and the second is built against the obfuscated version. Unfortunately the compile fails on the @Override as the interface does not have the throws clause.

I have proguard keeping the interface and all its members, but I can't figure out how to keep the throws clause.

like image 953
Cogsy Avatar asked Jul 12 '09 07:07

Cogsy


People also ask

What is a throws clause?

The throws clause in a method declaration serves two purposes: It tells the compiler which exceptions are thrown so that the compiler can report uncaught (checked) exceptions as errors. It tells a programmer who is writing code that calls the method what exceptions to expect.

Which type of exception must be caught with a throws clause?

The throws clause must be used with checked exceptions. The throws clause is followed by the exception class names. The throws clause is used in a method declaration. Using the throws clause, we can declare multiple exceptions at a time.

Can we change an exception of a method with throws clause from checked to unchecked while overriding it?

When a method in superclass throws an unchecked exception the method the subclass method overriding cannot throw a checked exception.


1 Answers

I figured it out.

-keepattributes Exceptions

like image 75
Cogsy Avatar answered Oct 28 '22 17:10

Cogsy