Click here to Skip to main content

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, embarrasing 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: How not to catch the exception PinmemberGastonV20-Jun-13 4:30 
GeneralSomething is not as I expected PinprofessionalMohibur Rashid19-Jun-13 22:40 
GeneralRe: Something is not as I expected PinmemberAmitosh Swain20-Jun-13 17:53 
GeneralRe: Something is not as I expected PinprofessionalMohibur Rashid20-Jun-13 22:25 
GeneralRe: Something is not as I expected PinmemberAmitosh Swain20-Jun-13 22:32 
GeneralRe: Something is not as I expected PinmemberRob Grainger23-Jun-13 23:57 
GeneralRe: Something is not as I expected PinmemberMember 467320212-Jul-13 13:11 
GeneralEverywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed19-Jun-13 20:28 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. Pinmembercjb11019-Jun-13 21:13 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed19-Jun-13 21:20 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberRob Grainger24-Jun-13 0:02 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberJarek Kruza19-Jun-13 21:56 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed19-Jun-13 22:08 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberJarek Kruza20-Jun-13 1:30 
Mohammed Hameed wrote:
So you mean you support placing try/catch blocks everywhere and catching the
main Exception everywhere, right?

Well it depens on your code structure...
 
Let's say you have the SaveRecord() method. This method is fired from UI and saves the record in DB.
Inside we have code dealing with database surrounded with try/catch(SQLException).
DB code throws SQLException as the DB is down, in catch we log the exception and throw custom RecordNotSavedExecption. UI part catches that and displays message to user.
Or returns false instead true, depending on your pattern.
That's the predictable and desired part.
 
Now if some other code in SaveRecord() throws OutOfMemoryException then we can:
1. Catch noting - we have OS/Framework unhandled exception. Bad.
2. We can catch all on application level (in one place in code), display generic error message to user, log the error and continue/close the app. Good.
3. We can catch generic Exception in SaveRecord(), log and throw custom RecordNotSavedExecption. Then we have above plus we just cancel the failing operation - not close the whole app. Better?
 
Mohammed Hameed wrote:
But I'm still not supporting this practice

There are many patterns and practices, generally it's good to suport just one. Wink | ;)
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberRob Grainger24-Jun-13 0:04 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed24-Jun-13 0:31 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberChris Ross 224-Jun-13 2:32 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberRob Grainger24-Jun-13 4:08 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalV.19-Jun-13 23:25 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed19-Jun-13 23:56 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. Pinmembercjb11020-Jun-13 0:12 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed20-Jun-13 0:26 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalV.20-Jun-13 0:31 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed20-Jun-13 1:11 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalRichard Deeming20-Jun-13 1:36 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalV.20-Jun-13 1:39 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinmemberAnalogNerd24-Jun-13 2:26 
GeneralRe: Everywhere a single Catch block used catching top Exception all times. PinprofessionalMohammed Hameed24-Jun-13 2:37 
GeneralRelational database reinvented as a flat file... Pinmemberjohnsyd19-Jun-13 19:58 
GeneralRe: Relational database reinvented as a flat file... PinprofessionalAlexCode19-Jun-13 20:25 
GeneralRe: Relational database reinvented as a flat file... Pinmemberjohnsyd19-Jun-13 21:22 
GeneralRe: Relational database reinvented as a flat file... PinprofessionalNormDroid19-Jun-13 20:43 
GeneralRe: Relational database reinvented as a flat file... PinprofessionalAlexCode19-Jun-13 21:26 
GeneralRe: Relational database reinvented as a flat file... PinprofessionalRichard Deeming20-Jun-13 1:32 
GeneralRe: Relational database reinvented as a flat file... Pinmemberjim lahey20-Jun-13 1:57 
GeneralWhy stick to just one database? Pinmemberjohnsyd19-Jun-13 17:52 
GeneralRe: Why stick to just one database? Pinmemberkrumia19-Jun-13 17:55 
GeneralRe: Why stick to just one database? Pinmemberjohnsyd19-Jun-13 18:07 
GeneralRe: Why stick to just one database? PinprofessionalPIEBALDconsult19-Jun-13 18:37 
GeneralRe: Why stick to just one database? Pinprofessionalvonb19-Jun-13 19:25 
GeneralRe: Why stick to just one database? PinprofessionalAlexCode19-Jun-13 20:23 
GeneralRe: Why stick to just one database? PinmemberAdriaan Davel19-Jun-13 21:55 
AnswerRe: Why stick to just one database? PinmemberGastonV19-Jun-13 20:28 
GeneralRe: Why stick to just one database? Pinmembercjb11019-Jun-13 21:15 
GeneralRe: Why stick to just one database? Pinmemberjohnsyd25-Jun-13 15:01 
GeneralRe: Why stick to just one database? PinmemberAdriaan Davel19-Jun-13 21:59 
GeneralRe: Why stick to just one database? PinprofessionalRichard Deeming20-Jun-13 1:30 
GeneralRe: Why stick to just one database? Pinmemberjim lahey20-Jun-13 2:04 
GeneralRe: Why stick to just one database? PinmemberNeverJustHere20-Jun-13 19:29 
GeneralRe: Why stick to just one database? Pinmemberjohnsyd25-Jun-13 15:15 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 28 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid