emrekose26 emrekose26 - 4 months ago 25
Android Question

Android studio try-catch suggestion for my method

I build my own library in Android and i want to give a warning about try-catch block when my method use

For example my library class like below

public class MyLib{
public void foo(){
// any code here
}
}


and the user's activity

MyLib lib = new MyLib();
lib.foo();


i want to here give a warning and after when the user press the Alt + Enter like below

MyLib lib = new MyLib();

try{
lib.foo();
}catch(Exception e){
}


is there code, annotation or configration about this?

Answer

When the IDE warns you about the unhandled exception, it means that the method throws a checked exception. This is what it should look like if your method throws an IOException:

public void foo() throws IOException {
}

Read more about checked exceptions here.

Comments