Try to perform these refactoring steps for only one error code at a time. Exceptions should be thrown only to inform of an error or critical situation. Avoid this! Don’t use exceptions to manage code execution. An exception handler can turn into a goto-like crutch. Unlike exceptions, error codes can’t be used in a constructor, since a constructor must return only a new object. Exception handlers are a much more succinct way to differentiate normal execution paths from abnormal ones.Įxception classes can implement their own methods, thus containing part of the error handling functionality (such as for sending error messages). Benefitsįrees code from a large number of conditionals for checking various error codes. Special error-handling code, which is ignored in normal conditions, is activated to respond. If a problem occurs, you “throw” an error, which is then “caught” by one of the exception handlers. In modern programming, error handling is performed by special classes, which are named exceptions. Returning error codes is an obsolete holdover from procedural programming.
0 Comments
Leave a Reply. |