some random crashes started to occur with very random error messages from the compiler.
Is your compiler actually crashing and giving you error messages? Or are you trying to say that your compiled program is crashing when you run it?
So, is there an alternative version of array/vector which actually throws and exception(or gives some message) when the index is outlimits?
In general you do not want throwing exceptions here since you never should access an invalid index in the first place. What you want is an assert (usually only enabled during debug builds but up to you). Of course with a decent compiler and a bit of debug info you should not even need that since you just run into a crash and then walk up the call stack until you see where your program tried to access an invalid index.
Would it be a better idea to actually inherit from vector/array and override the index operator?
Standard library containers are not intended to be inherited from. I have never seen a legitimate use for it either.
PD: The debugger won't help either in this case. The crashes are very random.
Of course the debugger helps even in those cases.
I hate std::vectors.
I love std::vector. There are legitimate reasons not to use it in specific circumstances but anyone 'hating' it probably does not understand it well enough and would run into the same or worse problems with something hand-rolled.
Edit: For example for gcc's typical standard library you can add define _GLIBCXX_DEBUG and get nice error messages like this:
C:/Qt/Qt5.5.0/Tools/mingw492_32/i686-w64-mingw32/include/c++/debug/vector:357:
error: attempt to subscript container with out-of-bounds index 10, but
container only holds 10 elements.
Objects involved in the operation:
sequence "this" @ 0x0028fe44 {
type = NSt7__debug6vectorIiSaIiEEE;
}
I believe MSVC automatically does a bounds check when you build the standard Debug configuration but I don't have it here to test at the moment and it's been a while since I was worried about that particular kind of error.