You can handle that by catching and handling SIGSEGV signal.
You can search in the forum there are several threads about it, or google it.