Easier RuntimeException handling

Answered

There are a lot of RuntimeExceptions out there, and if I want to do fine grained handling I need to know which ones can potentially be thrown. It would be very nice to get suggestions from the IDE which ones could be thrown and should be catched. With extra info, to know where it could come from.

1
3 comments
Avatar
Yaroslav Bedrov

Hello Jeff,

Could you please provide code example to clarify your request?

 

0
Avatar
Permanently deleted user

For example I'm using the feign library to do http requests:

public interface ServiceClient {

@RequestLine("GET /me")
User me();

}

@Configuration
public class ServiceFeignConfig {

@Value("${service.username}")
private String serviceUsername;
@Value("${service.password}")
private String servicePassword;
@Value("${service.url}")
private String serviceUrl;

@Bean
ServiceClient serviceClient() {
return Feign.builder()
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.logger(new Slf4jLogger(ServiceClient.class))
.logLevel(Logger.Level.BASIC)
.requestInterceptor(new BasicAuthRequestInterceptor(serviceUsername, servicePassword))
.target(ServiceClient.class, serviceUrl);
}
}

@Component
public class ServiceImpl {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(ServiceImpl.class);

private final ServiceClient serviceClient;

public ServiceImpl(ServiceClient serviceClient) {
this.serviceClient = serviceClient;
}

public User getMe(String language, String types) throws UserNotFoundException {
try {
User user = serviceClient.me();
} catch (RuntimeException e) {
log.error("Error!", e);
}

throw UserNotFoundException();
}
}

And in the ServiceImpl I want to do error handling, but I have no idea of the possible errors the feign library might throw at runtime.
So it would be nice to get a suggestion from the IDE which ones might be thrown.

0
Avatar
Yaroslav Bedrov

Jeff,

It should be possible after this fix: https://youtrack.jetbrains.com/issue/IDEA-126898

Could you please provide full project example to check why this features doesn't work right?

0

Please sign in to leave a comment.