PMP's suggestion works if the failed command sets a non-zero exit status (which almost all do). If it doesn't you need to capture the output and parse it for signs of success or failure
Code:
output="$(command 2>&1)"
The parsing is, of course, dependent on the particular command.