Error hiding: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
java example |
||
Line 23: | Line 23: | ||
'''end'''; |
'''end'''; |
||
'''end'''; |
'''end'''; |
||
Another example is the fact that accessing the contents of a file that does not exist in [[Java programming language|Java]] version 1.3 or older would result in an <code>IOException</code> without any reference to the missing file. |
|||
{{comp-stub}} |
{{comp-stub}} |
Revision as of 15:10, 12 June 2006
This article provides insufficient context for those unfamiliar with the subject. |
Error hiding is a common practice to hide error messages by overriding them with exception handling. The user will never know what really went wrong. Error hiding is an example of an anti-pattern.
Example:
try ImportFile(filename); except // a exception with almost no information raise Exception.Create('import failed'); end;
// better approach try ImportFile(filename); except on E:Exception do begin // build a informative message E.Message := 'Import of file <'+filename+'> failed.'+#13#10 + E.Message; // re-raise the exception raise; end; end;
Another example is the fact that accessing the contents of a file that does not exist in Java version 1.3 or older would result in an IOException
without any reference to the missing file.