I agree with djsoundfx in that we can't really help with a better explanation of what you are trying to do. Maybe a code sample would help as well.
And while the $? variable can be helpful, please be aware that if you put in a command with a pipe, $? returns the exit status of part of the command, but not the whole command. This can lead to some rather confusing results.
Maybe what you want is the || operator (assuming that you are using bash). It says, "do this if the previous command failed".
$ touch /abc.txt 2>/dev/null || echo "No can do. Not root."
Should fail as a general user will not be able to create a file in /.
So, in your case, you could do a ...
$ my_command || exit 999
Give each command a different exit status if you want to be able to see where in your script it actually bombed out.
And FYI, you can use && if you want to do something if the previous command completed succusfully.