I'm reading the Clean Code book from the Robert C. Martin series. And a very common situation was presented in my daily life.
public static void main(String[] args) {
String nome = null;
try {
if (nome.length() > 10) {
System.out.println("Nome maior que 10 caracteres");
} else {
System.out.println("Nome menor que 10 caracteres");
}
} catch (Exception e) {
// Não encontro o registro no banco de dados
}
}
Sometimes we perform some operation that the exception is unavoidable. In this code for example, when the exception happens in nome.length()
I want the error to be ignored.
I leave the comment to describe the reason for the error? Are you shooting the comment? Or can we work as another approach?
Remembering that I do not want to raise an exception!