Click here to Skip to main content
15,921,226 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: FileSystemObject not working Pin
Guffa4-Feb-06 9:08
Guffa4-Feb-06 9:08 
GeneralRe: FileSystemObject not working Pin
Quecumber2564-Feb-06 14:55
Quecumber2564-Feb-06 14:55 
GeneralRe: FileSystemObject not working Pin
Dave Kreskowiak4-Feb-06 15:13
mveDave Kreskowiak4-Feb-06 15:13 
Questionproperty sheets in vb6 ... Pin
Marc Soleda3-Feb-06 3:43
Marc Soleda3-Feb-06 3:43 
AnswerRe: property sheets in vb6 ... Pin
Dave Kreskowiak3-Feb-06 7:34
mveDave Kreskowiak3-Feb-06 7:34 
GeneralRe: property sheets in vb6 ... Pin
Marc Soleda4-Feb-06 0:05
Marc Soleda4-Feb-06 0:05 
QuestionODBC Driver error ERROR [IM002] Pin
dijudiju3-Feb-06 3:07
dijudiju3-Feb-06 3:07 
AnswerRe: ODBC Driver error ERROR [IM002] Pin
dijudiju7-May-06 21:24
dijudiju7-May-06 21:24 
QuestionCrystal report KeycodeV2.dll Pin
microuser_20003-Feb-06 1:11
microuser_20003-Feb-06 1:11 
AnswerRe: Crystal report KeycodeV2.dll Pin
Dave Kreskowiak3-Feb-06 8:38
mveDave Kreskowiak3-Feb-06 8:38 
GeneralRe: Crystal report KeycodeV2.dll Pin
microuser_20003-Feb-06 20:40
microuser_20003-Feb-06 20:40 
GeneralRe: Crystal report KeycodeV2.dll Pin
Dave Kreskowiak4-Feb-06 7:07
mveDave Kreskowiak4-Feb-06 7:07 
QuestionFinding Least & Max value Pin
Chandan_Kr3-Feb-06 0:11
Chandan_Kr3-Feb-06 0:11 
AnswerRe: Finding Least & Max value Pin
Steve Pullan3-Feb-06 0:51
Steve Pullan3-Feb-06 0:51 
GeneralRe: Finding Least & Max value Pin
Chandan_Kr3-Feb-06 19:43
Chandan_Kr3-Feb-06 19:43 
GeneralRe: Finding Least & Max value Pin
Steve Pullan5-Feb-06 12:17
Steve Pullan5-Feb-06 12:17 
QuestionError Handleing Pin
alien viper2-Feb-06 23:40
alien viper2-Feb-06 23:40 
AnswerRe: Error Handleing Pin
Steve Pullan3-Feb-06 0:03
Steve Pullan3-Feb-06 0:03 
AnswerRe: Error Handleing Pin
malharone3-Feb-06 6:19
malharone3-Feb-06 6:19 
First of all, you are using try/catch. So i'm assuming you're using VB.net. If so, then do not use legacy VB functions like "msgbox". Use "MessageBox.Show(..)".

Secondly, your first example displays the message to the user and will continue processing statements after the "End Try". Your second example, re-throws the exceptions back to the caller.

I think both of the examples are bad practice for error handling.

Alternate for Example 1:
Try<br />
  'Do Something<br />
Catch ex As Exception<br />
  Utilities.HandleError(ex)<br />
End Try

Advantages: You have a central error handling mecahnism. So if 2 weeks from today your boss tells you to start logging the errors to a text file, you wont have to change every "catch" statement but only the handler function. --> Refactoring

Alternate 1 for Example 2:
'Do Something
Advantages: In your example, you simply rethrow an exception without adding more information to it. By doing so, you actually lose critical error information -- such as inner exception and/or stack trace -- which is vital for finding the root of the problem. So simply remove try/catch block entirely.

Alternate 2 for Example 2:
Try<br />
'Do Something<br />
Catch ex As Exception<br />
Throw New Exception("Error opening your file", ex)<br />
End Try

Advantages: The advantage of this approach is that you mask the original exception message (which could be too technical for the user to understand) with your custom message without losing the original error. You're passing "ex" as an inner error so this way the caller can access both the user-friendly message and also the stacktrace of the original exception.

Hope this helps.

- Malhar
QuestionClass to convert HTML to text Pin
gaudenzio2-Feb-06 23:40
gaudenzio2-Feb-06 23:40 
AnswerRe: Class to convert HTML to text Pin
gaudenzio3-Feb-06 5:19
gaudenzio3-Feb-06 5:19 
QuestionCorp an Image in VB 6.0 Pin
miftha2-Feb-06 21:54
miftha2-Feb-06 21:54 
GeneralRe: Corp an Image in VB 6.0 Pin
bskirkman2-Feb-06 23:07
bskirkman2-Feb-06 23:07 
Questionusing DBNull.value Pin
raj kumar reddy2-Feb-06 19:39
raj kumar reddy2-Feb-06 19:39 
AnswerRe: using DBNull.value Pin
Rana Muhammad Javed Khan2-Feb-06 20:48
Rana Muhammad Javed Khan2-Feb-06 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.