Talk:Error hiding

message: Added link from anti-pattern.  I suggest we remove the linkless template.  It's a fact of life that some articles may only have one or two relevant links due to being highly specialised.  Stephenbooth uk 15:54, 2 October 2006 (UTC)
replies: text: The being no objections to my suggestion to remove the linkless template, I'll now remove it.--Stephenbooth uk 16:08, 8 October 2006 (UTC)
thread_title: Links

message: Error hiding has been around much longer than exception-handling programming languages. It has been a problem in the C programming language since its inception, and exceptions were included in C++ to try to catch the problem (no pun intended).
There are two ways to put error hiding into a C program. One way is to generate your own error message
without attempting to resolve errno:
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
 int main(int argc, char **argv)
 {
    FILE *file = fopen(argv[1], "r");
    if(FILE == NULL) {
        fprintf(stderr, "%s: cannot open\n", argv[1]);
        exit(1);
    }
    /* More error-hiding code follows */
 }
C code like that above is still being written today. The two ways to fix that error (under POSIX systems) are perror (which prints the error message for you) and strerror (which returns a string describing the error):
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
 int main(int argc, char** argv)
 {
    FILE *file = fopen(argv[1], "r");
    if(FILE == NULL) {
 #ifdef USE_PERROR
        perror(argv[1]);
 #elif defined(USE_STRERROR)
        fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
 #else /* Error hiding */
        fprintf(stderr, "Huh? Something's not right!\n");
 #endif
        exit(1);
    }
    /* More error-hiding code follows */
 }
The other way to create an error-hiding condition is by ignoring the return values of standard library functions. Programs that do this can crash just like C++ and Java programs that have empty catch blocks.
75.186.36.20 (talk) 22:39, 20 January 2008 (UTC)
thread_title:  Long history. 

message: Somethimes some sort of error hiding is needed (sorry if code is incorrect I hadn't used Java for some time):
  public interface SomeInterface {
    public void someMethod () throws SomeExceptions;
  }
  public class MyList implements SomeInterface {
    public void someMethod () throws SomeExceptions {
      try {
        doSomething ();
      } catch (OtherException e) {
        throw new RuntimeException (e);
      }
    }
  }
Otherwise the Java compiler will complain about throwing exception not specified. Or about throwing more exceptions in implementation then specified in interface (which cannot be easily changed as it is for example part of JDK). Uzytkownik (talk) 19:11, 26 March 2009 (UTC)
thread_title:  When error hiding is needed 

message: I've done a major edit to this page (diff here) to try and focus it on the actual primary topic that it's trying to tackle, and make it more neutral and less opinionated. The underlying primary topic here is, imo, exception swallowing and error swallowing, and "Error hiding" is just a symptom of a particular type of error swallowing. If I search for "exception swallowing" and "error swallowing" on google, this is the first hit :P
I've tried to incorporate all the major points of the previous version, and I've updated all the code examples to be more concise about what they're trying to exemplify. I would like to add examples of best practices at some point, but ran out of steam for the day.
More importantly, I'd like to rename this page to "Error swallowing", so I'm going to make a move request to discuss that.
Thoughts? Shana (talk) 18:52, 2 May 2019 (UTC)
thread_title:  Page rewrite and rename