Error hiding

Uses your system voice; voice and rate in settings.

Snapshot

≈ 5 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer programming, error hiding (or error swallowing) is the practice of catching an error or exception, and then continuing without logging, processing, or reporting the error to other parts of the software. Handling errors in this manner is considered bad practice and an anti-pattern in computer programming. In languages with exception handling support, this practice is called exception swallowing. Errors and exceptions have several purposes: * Help software maintainers track down and understand problems that happen when a user is running the software, when combined with a logging system * Provide useful information to the user of the software, when combined with meaningful error messages, error codes or error types shown in a UI, as console messages, or as data returned from an API (depending on the type of software and type of user) * Indicate that normal operation cannot continue, so the software can fall back to alternative ways of performing the required task or abort the operation. When errors are swallowed, these purposes can't be accomplished. Information about the error is lost, which makes it very hard to track down problems. Depending on how the software is implemented, it can cause unintended side effects that cascade into other errors, destabilizing the system.…

In computer programming, error hiding (or error swallowing) is the practice of catching an error or exception, and then continuing without logging, processing, or reporting the error to other parts of the software. Handling errors in this manner is considered bad practice and an anti-pattern in computer programming. In languages with exception handling support, this practice is called exception swallowing. Errors and exceptions have several purposes: Help software maintainers track down and understand problems that happen when a user is running the software, when combined with a logging system Provide useful information to the user of the software, when combined with meaningful error messages, error codes or error types shown in a UI, as console messages, or as data returned from an API (depending on the type of software and type of user) Indicate that normal operation cannot continue, so the software can fall back to alternative ways of performing the required task or abort the operation. When errors are swallowed, these purposes can't be accomplished. Information about the error is lost, which makes it very hard to track down problems. Depending on how the software is implemented, it can cause unintended side effects that cascade into other errors, destabilizing the system. Without information about the root cause of the problem, it's very hard to figure out what is going wrong or how to fix it. try { throw new Exception(); } catch { // do nothing } In this PowerShell example, the trap clause catches the exception being thrown and swallows it by continuing execution. The "I should not be here" message is shown as if no exception had happened. &{ trap { continue } throw write-output "I should not be here" } Exception swallowing can also happen if the exception is handled and rethrown as a different exception, discarding the original exception and all its context. In this C# example, all exceptions are caught regardless of type, and a new generic exception is thrown, keeping only the message of the original exception. The original stacktrace is lost, along with the type of the original exception, any exception for which the original exception was a wrapper, and any other information captured in the exception object. try { // do something } catch (Exception ex) { // maybe do some local handling of the exception throw new Exception(ex.Message); } A better way of rethrowing exceptions without losing information is to throw the original exception from the catch clause: try { // do something } catch (Exception ex) { // do some local handling of the exception throw; } Alternatively, a new exception can be created that wraps the original exception, so any other handlers will have access to both: try { // do something } catch(Exception ex) { // maybe do some local handling of the exception throw new CustomException(ex); } f, _ := "I should not be here", errors.New("") fmt.Print(f) In the case of C system calls, errors are indicated by the return value of the call being NULL, and error information is stored in a global errno variable. This code makes sure the file is valid before accessing it, but if fopen failed, the error is swallowed. FILE *file = fopen("", "r"); if (file) { // do something with the file }

Text derived from https://en.wikipedia.org/w/index.php?oldid=1340851092 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

Extracted from the cited revision's reference blocks; absent citations are not invented.