As many other posters have mentioned, typical CPUs do not have controls for invalid computations in hardware. Many of them would lock up in case of problems. Sometimes a hardware reset (wiping volatile memory) of the hole computer or its certain components would clear the issue. Computers as larger systems, comprised of also memory, storage, wiring/slots/contacts, further controllers, etc. do. Mission-critical ones are redundant to do same work many times and compare the outcomes.
In software, important things are covered by "assertions" - that is, verification that insane results do not appear in critical parts of code, like a = 2 + 2; assert (a == 4);
-- otherwise it crashes/restarts by design as the inputs/logic are not trustworthy. Generally it is safer to let programmers or sysadmins figure out the problem in real time than to corrupt data based on "garbage in - garbage out" if the work were to proceed.
There are programs designed to stress different parts of the computer, such as calculating Pi to the greatest precision possible, or rendering difficult scenes with GPU graphics (and comparing the rendered image to a stored model to count the artifacts), or just writing pre-known patterns into RAM and checking that they are read back successfully. This is most often employed by overclockers, who push their hardware to the speed (and thermal) limits above what the vendor specified as suitable for stable work. In fact, vendors do the same - checking say one chip out of a hundred from the same production batch and marking the whole batch based on the worst results (stable at lower frequencies/temperatures), so lucky buyers have a chance of getting individual devices which are more capable than is written on them. This is also done as part of troubleshooting - brownian movement does gnaw away at the the chips and their longevity, so eventually they are a mess of atoms that are no longer arranged as transistors. That can be tested with methods like this, whether by software or part of their firmware, on-demand or as a background maintenance job done by the device itself.
As I have dabbled with the ZFS filesystem from almost its beginning, I remember the pitches from its engineers about why they went about an integrated construct instead of separate layers (disks, virtual pool management/redundancy, logical volumes, filesystems...) practiced for decades before that. One crucial thing this allowed was end-to-end checksumming and redundancy managed holistically.
Remember I've mentioned wires and numerous controllers as parts of computers? "Passive" components do act up, it is a matter of time and statistics: cables are antennaes for EMI noise from fans and other motors (in the olden days, you could even hear HDD or CD-ROM spin-up in the wired headphones); sockets do get dusty and rusty over the years, causing ambiguous voltage levels (was it a 0 or 1?) or micro-sparks (unplug/plug cycles do help to scratch the bad top layer off the contact and let it work over a few more years of oxidation); bits in RAM or on disk (or nowadays in SSD quantum-law cages for electrons) are randomized by external energy (space radiation, general heat and brownian movement) or quantum effects (let's dissipate through an impenetrable power barrier just because we are a wave and can sometimes do that). Typical RAM also holds the information for just a short bit of time, being quick to read, write and forget, so its hardware constantly re-accesses the chips just to keep the memories fresh (which causes regular in-accessibilities for other work, which can be noticeable in real-time applications and may require those devices to use a different memory technology altogether).
This is largely why optical cabling is used - even in storage systems (to the extent that fiber-channel disks were connected by optical cable right from the HDD to the backplane of their rack box and beyond all the way to a server that used them, or part of them in a NAS/SAN setup) - to eliminate EMI interference.
Semi-active components like an insufficiently-powered PSU stretched close to its limits can also be a problem (when there's a burst load, its voltage minutely drops, and some 0's and 1's become hard to distinguish) even if we discount the EMI noise it can do or dried-up capacitors acting up.
Active components are even worse, way too many chipset manufacturers cut corners because some part of spec is too complicated to implement/test and too few layman users hit any problems - and hey, it is cheaper (more margin/bonus for those who save a buck)! A glaring example is "reset" support on USB hub devices, which is supposed to only programmatically recycle a connection to one device but often resets the whole hub or bus - disrupting everyone on it.
Same things did in fact happen with expensive storage back-planes (almost-passive boards where your 48 disks are plugged into and then are distributed to smart storage controllers), or more so with the less-expensive ones (IIRC SATA did not really have a concept of single-device/port reset... or just nobody implemented it... but my memory can be vague about this). So the ZFS community did in practice have to work around situations like "That one HDD did not respond for 30 sec, let's reset its link. Oops, here go all other disks becoming AWOL... and coming back after a while!" or sometimes reset storms ("...a disk went AWOL, let's reset it!" times 48 or so) causing outages too long to glaze over.
Thinking of capacitors mentioned earlier - those also have a role to play in storage (or not, if absent), such as safe flushing of buffered writes into the HDD or SSD devices when external power disappears. For efficiency, randomly targeted writes are typically "cached" - so they live in the device's little RAM chip for a while and then are burst out sequentially when a large enough block is collected. A loss of power can cause either the partially-written stuff to be committed to long-term storage, or worse - random garbage in random places. Bummer if that was your file system structure information.
And regarding hardware whose makers had cut corners - controllers capable of caching do add (and typically implement) commands to "flush" queued writes or otherwise fence them, so the software consumers like the operating system can "guarantee" that one transaction lands on the long-term storage before starting another operation. This is critical for example in filesystem metadata writes, where the obvious performance hit of un-cached writes is the lesser evil. Some controllers do lie (e.g. to win in benchmarks), and report a flushed write completed as soon as the request was received, while it is still cached and subject to getting lost or written out of order.
Redundancy comes in RAM (from ECC adding a few bits per byte to protect from single or dual bit flips, to whole RAID-like setups allowing a complete RAM module to die off), in storage (many HDDs storing same info), in controllers (those HDDs connected to different boards, so the whole board and its 8 or so disks can disappear without immediately fatal results) and of course in independent computers spread across the globe (what if a data center has a fire and all its devices get fried?)
Checksumming, at least as used in ZFS as the example I know best, allows it to compute a hash of each content block as soon as it is queued for writing, to store in the data tree (so this hash becomes part of content of a metadata block, and up the tree this goes until the "uber-block" which describes the current state of the storage system). This does assume that the RAM (or even CPU cache) and CPU logic were trustworthy in the split second that the content block was assembled and its checksum was calculated, but the rest of the system is effectively expected to lie sometimes (or "bit-rot" over time). Law of big numbers, bro.
The content and metadata blocks are scheduled separately and pass over the untrustworthy cabling, sockets, controllers, into disks. Metadata is typically written at least twice, and at distant LBA addresses from each other and the contents - so on rotating disks where this meant physically distant areas, a disk head crashing into the surface or some other mode of failure would hopefully only damage one copy. A completed ZFS transaction involves writing four uber-blocks in different parts of the device/partition (with checksums and locations of further metadata) so you can almost always find the newest reliable state of your data tree - if those metadata writes do happen as sequentially as they are queued and "flushed".
Whenever a read of ZFS metadata or content block happens, all the way through the tree, we know the expected checksum of the expected bit-length of the content (in a larger "cluster" if one is not fully populated by your smaller write) - and so the checksum of the read block is calculated and compared to the expectation. If they do not match, you instantly know something was corrupted and is no longer trustworthy. If you have redundancy (e.g. mirroring, such as enforced for the metadata part of the tree) you can read the other copy and hope (and check!) that it is intact - in that case, overwrite the bad copy with the good one. If not, you at least can report an error and not have the user trust that the garbage they received is what they had originally stored and expected to read back. Maybe they have a backup?..
Systems like this also practice regular "scrubbing" - e.g. weekly reads of the data pool just to confirm that all checksums match, and to repair whatever possible if they do not. (Similar to refreshes that RAM chips do many times a second - with repairs possible in the ECC and/or RAID-like setups).