I read code from one book and have this method:
public int getScore(String name) {
try {
//some code here
return score;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
Why this method in catch returns -1? Why not 5? Is that some convention?
You are the one choosing what you want to return as you are the only one who knows how you want to handle that returned value. I personally use
-1too when I want to detect an error, and I know a lot of people doing the same.