VBAHole22 Posted December 13, 2004 Posted December 13, 2004 Can anybody point to some resources about building my own error handling routines? What I have is a long process that involves calling several methods. During each method something could go wrong, in which case I want to avoid doing the remaining methods. What I would like would be a centralized error handler that could flip a boolean to let me know if something went wrong. i would then have to test this boolean before each method. Another reason I want to have this is because I see that I am writing the same 5 lines of code in each of my error handlers and anytime I see that I know there has to be a better way. Thanks for any suggestions Quote Wanna-Be C# Superstar
coldfusion244 Posted December 13, 2004 Posted December 13, 2004 Can anybody point to some resources about building my own error handling routines? What I have is a long process that involves calling several methods. During each method something could go wrong, in which case I want to avoid doing the remaining methods. What I would like would be a centralized error handler that could flip a boolean to let me know if something went wrong. i would then have to test this boolean before each method. Another reason I want to have this is because I see that I am writing the same 5 lines of code in each of my error handlers and anytime I see that I know there has to be a better way. Thanks for any suggestions Why not use Try/Catch/Throw/Finally...Link Quote -Sean
VBAHole22 Posted December 13, 2004 Author Posted December 13, 2004 I am using that. But when you call a method and that method calls another method and all of your try catch blocks look like try ....do something catch ex as Exception MessageBox Alert Console.WriteLine finally Conn.close end try You have a problem. First of all you cannot easily change platforms from say an asp.net page to an asp.net web service (which I have had to do a few times). because one supports console.writeline and the other does not. If this code were centralized then the problem goes away with one fix. Incidentally, it seems to me that the most reliable way to write out error information across all platforms is the text file. I drop this in all my code now Private Sub ToText(ByVal TextNote As String) If Not CType(AppSettings("Log"), Boolean) Then Exit Sub Dim path As String Dim fi As FileInfo Dim sw As StreamWriter Try path = AppSettings("LogFilePath") fi = New FileInfo(path) sw = fi.AppendText sw.WriteLine(TextNote) sw.Flush() sw.Close() Catch ex As Exception Finally sw = Nothing End Try End Sub Basically what I am looking for is a more organized approach to the error handling where I can centralize my error reporting code and get information about where and when the error took place and what led up to it. I could also put email code in there to. Quote Wanna-Be C# Superstar
Administrators PlausiblyDamp Posted December 13, 2004 Administrators Posted December 13, 2004 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/emab-rm.asp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VBAHole22 Posted December 13, 2004 Author Posted December 13, 2004 Sweet. Thank you. I've gotten to a point in programming where I can tell that something i'm doing can be done a better way, I just can't figure out the way most times. :rolleyes: Quote Wanna-Be C# Superstar
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.