Here’s a question where my real world programming inexperience shines through. I have a function which makes a call to three other functions:
Public Sub StartService()
RunSearch()
SaveMessages()
DeleteMessages()
End Sub
within each of the methods RunSearch(), SaveMessages() and DeleteMessages() I am using Try Catch statements to catch errors. Right now I catch the error and write to an error log when RunSearch() errors out, but I’m also get two errors from SaveMessages() and DeleteMessages() because these functions are dependent upon RunSearch() not returning an error. I am trying to build good a error catching foundation so I don’t just want to kill the app when there’s an error. My question is this: How can I gracefully stop execution if an error occurs in RunSearch().
Why does
RunSearchnot rethrow the exception after logging the problem?If you don’t want to call
SaveMessages()ifRunSearch()fails then don’t code it that way.My general thought is that each method’s interface is specifying a “protocol”. It must state its behaviour in the event of problems. Approaches include: