[go: nahoru, domu]

Jump to content

Error hiding

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 80.35.238.49 (talk) at 09:44, 1 June 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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;