I guess with programming, you can never get 100% certainty when it comes to correctness of your code - Unless you perform formal analysis which is impractical for most use cases.
You might not succeed at 100%, but you can remove "classes of error" by adopting particular styles or techniques backed by formal analysis. That's one of the biggest appeals of compiler technology - it can encode an understanding of patterns proven to detect failure, and in so doing lower your resulting bug count.