Answer the question
In order to leave comments, you need to log in
Which is better: handle the exception or not throw it?
Let's say I have a list
and what would be the best way to do it?
So:
var list = new List<int> { 1, 2, 3, 4 };
int getValue(int index) {
try {
return list[index];
}
catch (ArgumentOutOfRangeException ex) {
return -1;
}
}
int getValue(int index) {
if (index < list.Count) {
return list[index];
}
else {
return -1;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question