Staying safe is important.
Make sure to bring enough water when going into a desert.
Better just avoid them. If you insist... well...
In countries and cities that are known for robberies it can be a good idea to use a separate wallet. Another option is to keep a stash of something between 20 and 50 USD at hand to quickly "buy" your way out.
- this is a stub, please add more information