Daklu Posted April 18, 2010 Report Share Posted April 18, 2010 Designing good error handling systems for applications can be tough. Typically in my apps each layer will handle the errors it can and if it can't it passes the error up to the layer above it. There's a downside to this strategy--it unrolls the call stack. Suppose I have a process executing in a lower layer that needs to execute for 5 minutes. Two minutes into the process an error occurs which that layer doesn't know how to handle, so the call stack unrolls until it finds a vi that does know how to handle the error. There's no good way to continue my process from the 2 minute mark without extensive bookkeeping to keep track of the state of the lower layer when the error occurred. Notifying users of errors is another scenario where I run into this problem. I may want to prompt the user to Continue or Abort on an unhandled low layer error, but I don't want to embed dialog boxes in those lower layers. (Makes reuse harder.) Once the error propogates up the call stack to a higher layer I've lost my state and Continuing is no longer an option. I've had the idea of using the Chain of Responsibility pattern as an error handling strategy bouncing around in my head for a while. Building an error handling Chain of Responsibility essentially creates a separate call stack specifically for errors. Instead of an errors propagating up the call stack until something handles it, errors invoke the error handling chain. This allows higher level layers to handle errors that occurred at lower levels without exiting the lower level vis. In principle I think this could be a powerful technique. In practice I have no idea how well it would work or how much complexity it would add. Has anyone ever tried anything like this? CoR is run time construct so each layer would have to know when to add/remove its error handling routines to/from the chain. I'm not sure if there's a clean way (in terms of both code clarity and run time efficiency) to manage that. Are there other, simpler ways to handle the problem I described above? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.