Click here to Skip to main content
15,885,278 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Parsing string to Integer with try and catch??? PinPopular
Pete O'Hanlon25-Sep-12 2:04
mvePete O'Hanlon25-Sep-12 2:04 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi25-Sep-12 2:57
protectorMarco Bertschi25-Sep-12 2:57 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:34
dojohansen2-Oct-12 3:34 
GeneralRe: Parsing string to Integer with try and catch??? Pin
OriginalGriff25-Sep-12 3:32
mveOriginalGriff25-Sep-12 3:32 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi25-Sep-12 3:36
protectorMarco Bertschi25-Sep-12 3:36 
GeneralRe: Parsing string to Integer with try and catch??? Pin
KP Lee28-Sep-12 22:17
KP Lee28-Sep-12 22:17 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi30-Sep-12 21:01
protectorMarco Bertschi30-Sep-12 21:01 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:48
dojohansen2-Oct-12 3:48 
Parse is not significantly slower than TryParse. (I suspect if you have a look with Reflector, you'll find it uses TryParse under the hood. Academically speaking I suppose it must in that case be slower, but in practice the difference would be insignificant at best.)

But Parse in conjunction with try-catch is obviously a LOT slower than TryParse in conjunction with "if". And it's not necessary for the stack to be deep for this to be the case. Throwing an exception means allocating a new object (the exception) on the heap and this alone makes it far more costly. If you experiment a little with a simple console or winforms app you'll note that the first time you throw and catch an exception incurs a noticeable delay. After that it is a lot faster, but still thousands of times slower than returning a bool.
GeneralRe: Parsing string to Integer with try and catch??? PinPopular
BobJanova25-Sep-12 3:53
BobJanova25-Sep-12 3:53 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi25-Sep-12 4:05
protectorMarco Bertschi25-Sep-12 4:05 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Julien Villers25-Sep-12 23:45
professionalJulien Villers25-Sep-12 23:45 
GeneralRe: Parsing string to Integer with try and catch??? Pin
BobJanova26-Sep-12 0:12
BobJanova26-Sep-12 0:12 
GeneralRe: Parsing string to Integer with try and catch??? Pin
Julien Villers26-Sep-12 1:15
professionalJulien Villers26-Sep-12 1:15 
GeneralRe: Parsing string to Integer with try and catch??? Pin
dojohansen2-Oct-12 3:51
dojohansen2-Oct-12 3:51 
GeneralRe: Parsing string to Integer with try and catch??? Pin
agolddog28-Sep-12 3:44
agolddog28-Sep-12 3:44 
AnswerRe: Parsing string to Integer with try and catch??? Pin
Marco Bertschi28-Sep-12 4:04
protectorMarco Bertschi28-Sep-12 4:04 
GeneralRe: Parsing string to Integer with try and catch??? Pin
zenwalker19859-Oct-12 17:58
zenwalker19859-Oct-12 17:58 
GeneralHappy debugging! PinPopular
Andrei Straut23-Sep-12 22:12
Andrei Straut23-Sep-12 22:12 
GeneralRe: Happy debugging! Pin
Brisingr Aerowing24-Sep-12 2:54
professionalBrisingr Aerowing24-Sep-12 2:54 
GeneralRe: Happy debugging! PinPopular
Patrice STOESSEL24-Sep-12 19:40
Patrice STOESSEL24-Sep-12 19:40 
GeneralRe: Happy debugging! Pin
Andrei Straut24-Sep-12 20:09
Andrei Straut24-Sep-12 20:09 
GeneralRe: Happy debugging! Pin
Sentenryu25-Sep-12 0:11
Sentenryu25-Sep-12 0:11 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 0:40
Andrei Straut25-Sep-12 0:40 
GeneralRe: Happy debugging! Pin
DerekT-P25-Sep-12 1:01
professionalDerekT-P25-Sep-12 1:01 
GeneralRe: Happy debugging! Pin
Andrei Straut25-Sep-12 1:07
Andrei Straut25-Sep-12 1:07 

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.