Click here to Skip to main content
15,896,153 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: Catch an Exception... then throw it? Pin
Rod Kemp27-Nov-10 20:20
Rod Kemp27-Nov-10 20:20 
GeneralRe: Catch an Exception... then throw it? Pin
Sandeep Mewara27-Nov-10 19:57
mveSandeep Mewara27-Nov-10 19:57 
GeneralRe: Catch an Exception... then throw it? Pin
doja9328-Nov-10 7:54
doja9328-Nov-10 7:54 
GeneralRe: Catch an Exception... then throw it? Pin
Rod Kemp28-Nov-10 15:04
Rod Kemp28-Nov-10 15:04 
GeneralRe: Catch an Exception... then throw it? Pin
Chadwick Posey29-Nov-10 5:34
Chadwick Posey29-Nov-10 5:34 
GeneralRe: Catch an Exception... then throw it? Pin
Sean Sterling28-Nov-10 20:22
Sean Sterling28-Nov-10 20:22 
GeneralRe: Catch an Exception... then throw it? [modified] Pin
mohan5k29-Nov-10 1:12
professionalmohan5k29-Nov-10 1:12 
GeneralRe: Catch an Exception... then throw it? Pin
Rod Kemp29-Nov-10 18:39
Rod Kemp29-Nov-10 18:39 
mohan5k wrote:
I do not really understand why we have to catch the exception and throw it.

For your own code where you write the functions and you call them and you know you will catch and handle any exceptions it is not required that in your example function2 has a try/catch that re-throws the exception.
Where it does come in handy is when you are writing code that other people will use, in this case you may want to log all errors do you trust that the people using your code will do this for you or do it correctly, no you don't, you catch all errors log them then re-throw them back to the calling code or you may only want to re-throw errors under specific conditions such as if you are catching the SQLExceptions and get SQL Error 1205 (deadlock) you may want to retry the operation where as all other errors you may throw back to the calling code.
How you use it depends on what you are doing and how you expect it to be handled.
People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs

GeneralRe: Catch an Exception... then throw it? Pin
mohan5k30-Nov-10 20:00
professionalmohan5k30-Nov-10 20:00 
GeneralRe: Catch an Exception... then throw it? Pin
Bob Doran29-Nov-10 4:45
Bob Doran29-Nov-10 4:45 
GeneralRe: Catch an Exception... then throw it? Pin
taoklerks28-Nov-10 22:10
taoklerks28-Nov-10 22:10 
GeneralRe: Catch an Exception... then throw it? Pin
Rod Kemp28-Nov-10 22:44
Rod Kemp28-Nov-10 22:44 
GeneralRe: Catch an Exception... then throw it? Pin
Spectre_00129-Nov-10 2:32
Spectre_00129-Nov-10 2:32 
GeneralRe: Catch an Exception... then throw it? Pin
Kirk Wood29-Nov-10 14:26
Kirk Wood29-Nov-10 14:26 
GeneralRe: Catch an Exception... then throw it? Pin
Rod Kemp29-Nov-10 18:03
Rod Kemp29-Nov-10 18:03 
GeneralRe: Catch an Exception... then throw it? Pin
musefan30-Nov-10 2:46
musefan30-Nov-10 2:46 
GeneralRe: Catch an Exception... then throw it? Pin
RobCroll27-Nov-10 23:26
RobCroll27-Nov-10 23:26 
GeneralRe: Catch an Exception... then throw it? Pin
Jeroen De Dauw28-Nov-10 4:00
Jeroen De Dauw28-Nov-10 4:00 
GeneralRe: Catch an Exception... then throw it? Pin
PIEBALDconsult28-Nov-10 5:08
mvePIEBALDconsult28-Nov-10 5:08 
GeneralRe: Catch an Exception... then throw it? Pin
AspDotNetDev28-Nov-10 9:27
protectorAspDotNetDev28-Nov-10 9:27 
GeneralRe: Catch an Exception... then throw it? Pin
Adriaan Davel29-Nov-10 18:26
Adriaan Davel29-Nov-10 18:26 
GeneralRe: Catch an Exception... then throw it? Pin
mindserve19-Dec-10 13:00
mindserve19-Dec-10 13:00 
GeneralRe: Catch an Exception... then throw it? Pin
musefan30-Nov-10 2:53
musefan30-Nov-10 2:53 
GeneralIs this how we deprecate now? PinPopular
TheyCallMeMrJames26-Nov-10 5:48
TheyCallMeMrJames26-Nov-10 5:48 
GeneralRe: Is this how we deprecate now? Pin
oggenok6426-Nov-10 10:37
oggenok6426-Nov-10 10:37 

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.