They cannot be 100% sure of a bug free system. They can increase their confidence that the system is bug-free by use of static analysis and testing. Some people advocate bebugging as a way of estimating how many bugs remain in a system. There are at least two forms of static analysisleast two forms of static analysis.
If the system goes wrong then it goes wrong. There are assorted methods to reduce the impact of failures. Having code that checks for consistency and then abandoning a transaction or even restarting a process or the entire system is common One way of doing this uses assertions. To ensure systems restart after some types of failure Watchdog timers are frequently used.