The following code exits with a unbound variable error. How to fix this, while still using the set -o nounset option?
#!/bin/bash
set -o nounse         
        
While this isn't exactly the use case asked for above, I've found that if you want to use nounset (or -u) the default behavior is the one you want: to exit nonzero with a descriptive message.
It took me long enough to realize this that I figured it was worth posting as a solution.
If all you want is to echo something else when exiting, or do some cleanup, you can use a trap.
The :- operator is probably what you want otherwise.