I have the following method, which needs to return a List, but exceptions might occur along the way, and I don't want to handle them in my application, mainly because I don't even know how to handle them. The idea is simple: read data from a CSV file and return the list instantiated using the 'Beans' logic in OpenCSV. The problem is the exceptions. Since I only want the error and stack trace to be printed in the console and the application to be terminated, what is the best approach to deal with this? Should I use throw? Should I use catch? The problem with catch is that the compiler complains that a return is missing, even if I provide it inside the try. This is not for a real application; it's just a simple study project, so if something goes wrong, I just want to know what happened and have the program terminate, nothing more.
public static List<Usuario> ler() {
try (FileReader reader = new FileReader(UsuarioArquivo.getCaminho().toString())) {
return new CsvToBeanBuilder<Usuario>(reader)
.withType(Usuario.class)
.build()
.parse()
;
}
}