While errors can be beneficial for learning, true guesses are not terribly useful. As the confidence in an error increases, learning from the error also increases (called the hypercorrection effect). There is quite a bit of research to support the idea that participants have heightened attention or perhaps surprise when they believe an answer is correct and are told that they are wrong. That research includes behavioral laboratory research in addition to neuroscience research that shows activity in an area of the brain that is used when we have heightened attention.
There are a few exceptions to the hypercorrection effect. Individuals with amnesia obviously have a difficult time learning and have been shown to be able to learn some without errors instead. Older adults learn from errors, but they learn about equally from errors with low and high confidence. They seem to have the same amount of attention to errors made with different levels of confidence.
One possible explanation for why we learn from errors has to do with what cognitive psychologists call “reconsolidation”. Each time we bring something to mind, we create a new memory trace, allowing us to change the memory. So, when we retrieve an incorrect piece of information and are corrected, we are able to lay down a new trace to incorporate the new information.