you cannot use $!,
1) It is only meaningful, if you check it right after the failure. However you are tryinh to check it after a functuion returned, and at that moment, $! could be changed long time ago;
2) $! is usually set by system or library calls.