Test Driven Development can help, although there are skills needed, and you can have errors in your tests!
But the skills needed to write/troubleshoot a good test are more focused/limited than being able to code
Tests also encourage you to write testable code, which is usually modular/functional, and broken code elsewhere is less likely to affect it.
Monolithic code is hard to test/debug.