You seem to have a misconception regarding how error handling works in C and what happens in exceptional cases.
There are certain things a C program can do that will give rise to undefined behavior. Attempting to call free on a pointer that was not returned by malloc is one of those things.
When undefined behavior happens, the C standard imposes no requirements on what the program will do. It could crash, it could output strange results, or it could appear to work properly (and possibly crash later at a seemingly unrelated point).
So attempting to capture what will happen when you call free(hello) makes no sense in part because there's no guarantee something "bad" will happen at that time. So even if you were to (for example) set up a signal handler for SIGSEGV it might not trigger, and even if it does you program will be in such a state that there's nothing you can really do to "clean up".
So to summarize, given the question of how to capture undefined behavior: don't cause undefined behavior.
That being said, there are tools such as Valgrind that can detect memory management errors so that they can be prevented from happening in the first place.
helloso you cannot (and must not) free it. All allocations are released when your program exits (or crashes) anyway.strcpyorfreesimply cannot fail gracefully. Causing a segfault with a call tostrcpyis not at all analogous to, for instance, raising anIllegalArgumentExceptionin Java. Attempting to recover from misuse of a function is not sane in C.