Error Handling OOA/OOD xuyingxiao@126.com
Error Handling OOA/OOD xuyingxiao@126.com
Error Handling patterns Big Outer Try Block Hide Technical Detail from Users Log at Distribution Log Unexpected Boundary Errors Unique Error Split Domain and Make Exceptions Identifier Technical errors Exceptional
Error Handling Patterns
plit Domain and Technical Errors domain errors'' are due to errors in the business logic or business processing(e. g. wrong type of customer for insurance policy) technical errors", are caused by problems in the underlying platform(e.g, could not connect to database)or by unexpected faults(e.g. divide by zero e Handling technical errors in domain code makes this code more obscure and difficult to maintain
Split Domain and Technical Errors “domain errors”, are due to errors in the business logic or business processing (e.g. wrong type of customer for insurance policy). “technical errors”, are caused by problems in the underlying platform (e.g. could not connect to database) or by unexpected faults (e.g. divide by zero). Handling technical errors in domain code makes this code more obscure and difficult to maintain
e Solution Split domain and technical error handling Create separate exception/error hierarchies and handle at different points and in different ways as approprlate
Solution Split domain and technical error handling. Create separate exception/error hierarchies and handle at different points and in different ways as appropriate
Domain Exception System exception CustomerNotFound Exception InsufficientFunds Exception Transaction Refused Exception
e public class DomainEXception extends Exception Public class InsufficientFunds Exception extends . Exception public class SystemEXception extends Exception
public class DomainException extends Exception { ... } Public class InsufficientFundsException extends …Exception { ... } public class SystemException extends Exception { ... }
public float withdrawFunds (float amount e throws InsufficientFunds Exception, SystemException Domain code that could generate various errors both technical and domain catch(Domain Exception ex throw ex catch(Exception ex) throw new SystemException(ex)
public float withdrawFunds(float amount) throws InsufficientFundsException, SystemException { try { // Domain code that could generate various errors // both technical and domain } catch (DomainException ex) { throw ex; } catch (Exception ex) { throw new SystemException(ex); } }
Error Handling patterns Big Outer Try Block Hide Technical Detail from Users Log at Distribution Log Unexpected Boundary Errors Unique Error Split Domain and Make Exceptions Identifier Technical errors Exceptional
Error Handling Patterns
Big outer Try Block e Errors will propagate right to the edge of the system and will appear to crash the application if not handled at that point e Users are mostly on remote sites and will not do much to report errors
Big Outer Try Block Errors will propagate right to the edge of the system and will appear to “crash” the application if not handled at that point. Users are mostly on remote sites and will not do much to report errors
e Solution e Implement a Big Outer Try Block at the "edge" of the system to catch and handle errors that cannot be handled by other tiers of the system. The error handling in the block can report errors in a consistent way at a level of detail appropriate to the user constituency
Solution Implement a Big Outer Try Block at the “edge” of the system to catch and handle errors that cannot be handled by other tiers of the system. The error handling in the block can report errors in a consistent way at a level of detail appropriate to the user constituency