Click here to Skip to main content
16,006,382 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Silently blocking all keyboard input for RichTextBox Pin
supercat914-Nov-07 9:37
supercat914-Nov-07 9:37 
Questionhow to locate wifi node Pin
umershahbaz14-Nov-07 6:30
umershahbaz14-Nov-07 6:30 
AnswerRe: how to locate wifi node Pin
Dave Kreskowiak14-Nov-07 7:12
mveDave Kreskowiak14-Nov-07 7:12 
AnswerRe: how to locate wifi node Pin
Baddog_52017-Nov-07 16:23
Baddog_52017-Nov-07 16:23 
QuestionExeption handling in VB.net Pin
supercat914-Nov-07 6:19
supercat914-Nov-07 6:19 
AnswerRe: Exeption handling in VB.net Pin
Dave Kreskowiak14-Nov-07 6:57
mveDave Kreskowiak14-Nov-07 6:57 
GeneralRe: Exeption handling in VB.net Pin
supercat914-Nov-07 9:02
supercat914-Nov-07 9:02 
GeneralRe: Exeption handling in VB.net Pin
Dave Kreskowiak14-Nov-07 10:20
mveDave Kreskowiak14-Nov-07 10:20 
Yes, catch-all Try/Catch blocks are frowned upon. Generally, people who use them just eat the error and don't report it, then wonder why their code doesn't work.

Yes, you should be looking up methods and function to see what exceptions they can throw. Then you can write your code to handle those specific cases. Generally, just trapping the root Exception class is a bit expensive because the Try/Catch block first sees if there is a handler for the specific exception. If there isn't one, then it looks to see if there is a handler for the parent class of the exception, and so on up the inheritence chain until it reaches the base Exception class.

I really don't recommend using the CDbl function anymore when Double.Parse and Double.TryParse are available. You get a bit more robust capability with the .NET conversion and type classes. For instance, Double.Parse will throw one of three exceptions if the value cannot be parsed into a double. Double.TryParse will never throw an exception, but instead returns a True/False value to indicate of the value was successfully converted or not.

You normally don't check the text representation of number for the correct format first. You try the conversion, and if it works, you then validate the returned number for proper range. If this entire process doesn't work, then your code can throw it's own exception. Seeing if a string will successfully convert to a number, regardless of localization, isn't really practical. You're trying to avoid having the conversion throw an exception, when that should not be your focus. You should be TRYING the conversion, then either throw your own exception if the conversion fails, or returning the validated value of the conversion.

It sounds like you're trying to do the conversion and validation backwards. It's far easier to validate the data in its native type than it is to validate it as a simple string. Convert the data to it's native type first, and if that works, validate the converted value. If that passes, then you've got a good value. But if either of those steps fails, then your conversion code should throw it's own exception.


A guide to posting questions on CodeProject[^]

Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: Exeption handling in VB.net Pin
supercat914-Nov-07 10:45
supercat914-Nov-07 10:45 
GeneralRe: Exeption handling in VB.net Pin
Dave Kreskowiak14-Nov-07 10:53
mveDave Kreskowiak14-Nov-07 10:53 
GeneralRe: Exeption handling in VB.net Pin
supercat914-Nov-07 12:05
supercat914-Nov-07 12:05 
AnswerRe: connection to SQL server stays open Pin
Dave Kreskowiak14-Nov-07 6:11
mveDave Kreskowiak14-Nov-07 6:11 
QuestionNibbles Pin
No-e14-Nov-07 6:05
No-e14-Nov-07 6:05 
AnswerRe: Nibbles Pin
Dave Kreskowiak14-Nov-07 6:26
mveDave Kreskowiak14-Nov-07 6:26 
GeneralRe: Nibbles Pin
supercat914-Nov-07 6:30
supercat914-Nov-07 6:30 
GeneralRe: Nibbles Pin
Dave Kreskowiak14-Nov-07 6:49
mveDave Kreskowiak14-Nov-07 6:49 
GeneralRe: Nibbles Pin
supercat914-Nov-07 6:56
supercat914-Nov-07 6:56 
GeneralRe: Nibbles Pin
Dave Kreskowiak14-Nov-07 7:16
mveDave Kreskowiak14-Nov-07 7:16 
GeneralRe: Nibbles Pin
supercat914-Nov-07 9:40
supercat914-Nov-07 9:40 
GeneralRe: Nibbles Pin
Dave Kreskowiak14-Nov-07 12:57
mveDave Kreskowiak14-Nov-07 12:57 
GeneralRe: Nibbles Pin
nlarson1114-Nov-07 7:40
nlarson1114-Nov-07 7:40 
GeneralRe: Nibbles Pin
Dave Kreskowiak14-Nov-07 8:22
mveDave Kreskowiak14-Nov-07 8:22 
GeneralRe: Nibbles Pin
nlarson1114-Nov-07 8:26
nlarson1114-Nov-07 8:26 
Questionform closing error Pin
Tom Deketelaere14-Nov-07 4:07
professionalTom Deketelaere14-Nov-07 4:07 
AnswerRe: form closing error Pin
Dave Kreskowiak14-Nov-07 6:24
mveDave Kreskowiak14-Nov-07 6:24 

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.