How to respond to/read exit code in bash

Sometimes you need to respond to/read exit codes in bash/Linux CLI.

This is how I do it:

produces_err="$(ls /non-existent-dir)"
if [[ $? == 0 ]]; then
        echo "No err"
else
        echo "Err"
fi