I am sporadically getting "Segmentation fault" error. googling says that it happens when the program is trying to write to a memory segment that it does not have access to.
I use try-catch block on the out most program function (as below) but still my program shuts down abruptly without even going into catch block.
Reading and writing to invalid memory locations doesn't throw exceptions. It is undefined behaviour so the C++ standard gives no guarantees on what will happen.
If you want to find out where the problem occur you can use a memory debugger such as valgrind.
Thanks for the suggestion, I use STL vector in some other places but here I need my code to be as fast as possible hence the C-style array. vector is probably adding some performance overhead for all those niceties.
It's just I remember getting more meaningful messages for array out of bounds error when I was coding with Visual C++ & Windows - not that I regret abandoning Windows :)
std::vector::operator[] shouldn't have any overhead with optimizations turned on. You can enable bounds checking for std::vector::operator[] (and other things like iterators) by defining the macro _GLIBCXX_DEBUG. That way you can have bounds checking while testing and when you later want speed you just remove it.
Getting "Segmentation Fault" tells us that it doesn't work, but it's not enough for debugging. Can you try running ns2 with gdb and post the output you get?