Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically adding/removing checked exceptions while prototyping

I would rather not add/remove throws clauses manually, especially while prototyping. Is there a batch refactoring tool that adds/removes throws clauses to every method to reflect the code? After all, the compiler tells you what exceptions a method may throw, therefore maybe a tool exists that uses that information to manipulate throws clauses.

EDIT: Before I clarified that I am looking for a batch tool, somebody has mentioned a manual intervention via IDE, but this is not what I am looking for. I am looking for a batch utility.

like image 522
Eleno Avatar asked Mar 17 '26 08:03

Eleno


1 Answers

ProjectLombok has a wonderful feature called SneakyThrows (It may fit your use case in prototyping.)

From their website you can do the following without a compile error :

@SneakyThrows(UnsupportedEncodingException.class)
public String utf8ToString(byte[] bytes) {
  return new String(bytes, "UTF-8");
}

@SneakyThrows
public void run() {
  throw new Throwable();
}
like image 173
rjdkolb Avatar answered Mar 20 '26 00:03

rjdkolb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!