How to protect code from crashes in this situation

Posted by Davit Siradeghyan on Stack Overflow See other posts from Stack Overflow or by Davit Siradeghyan
Published on 2010-04-17T10:56:29Z Indexed on 2010/04/17 11:03 UTC
Read the original article Hit count: 405

int arr[ 5 ] = { 0 };

int i = 8; // out of bounds

arr[ i ] = 8;

I know that I can just check i like this if( i < 0 || i > 5 ) ....

I also know about SEH in Visual Studio, but it looks like not working solution.

__try { /* code */ }

__except(GetExceptionCode() == EXCEPTION_ARRAY_BOUNDS_EXCEEDED)

This is not working. As I see SEH working in situations like divide to 0, access protected pages ... How can I protect my program from crashes?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-studio-2008