My senior colleague tells me to wrap every method within a try-catch block so they can trace where exceptions occurs to help debug issues quicker. Is it better to wrap every method in a Try Catch such as this to:
Public int foo()
{
try
{
//do something
}catch(Exeception ex)
{
//do something with ex
}
}
Or is it better to catch exceptions where I think they may occur? E.g. doing something with an array may cause the IndexOutOfRangeException
will occur.
//wrap this in try catch
int[] array = new int[3];
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
Thanks.
See Question&Answers more detail:os