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: Try/catch block... PinmemberRichard Deeming21-Nov-12 2:23 
GeneralRe: Try/catch block... Pinmemberwarriordog21-Nov-12 2:27 
GeneralRe: Try/catch block... PinmemberReese Currie21-Nov-12 2:52 
GeneralRe: Try/catch block... Pinmemberbkebamc21-Nov-12 5:17 
GeneralRe: Try/catch block... PinmemberH.Brydon21-Nov-12 16:34 
GeneralRe: Try/catch block... PinmemberBernhard Hiller21-Nov-12 20:27 
GeneralRe: Try/catch block... Pinmemberlukeer22-Nov-12 21:06 
GeneralRe: Try/catch block... PinmemberKP Lee26-Nov-12 7:41 
Richard Deeming wrote:
If that's C#, it won't compile; you'll get a "Control cannot leave the body of a finally clause" compiler error.
I had to play around. You can throw an error in the try/catch/finally segments and it will compile. Since I didn't enclose the routine in a try catch, the finally segment did blow up with an unhandled exception. Then I did put it in that logic:
            try
            {
                int junk = trycat();
            }
            catch (Exception ex)
            {
                Console.WriteLine("caught exception {0}", ex.Message);
                Console.ReadKey();
            }
...
        static int trycat()
        {
            try
            {
                throw (new Exception("Throwing an exception in try block"));
            }
            catch
            {
                throw (new Exception("Throwing an exception in catch block"));
            }
            finally
            {
                throw (new Exception("Throwing an exception in finally block"));
            }
            return 1;
        }

GeneralRe: Try/catch block... PinmemberGary R. Wheeler21-Nov-12 4:26 
GeneralRe: Try/catch block... PinmemberPhilLenoir21-Nov-12 6:36 
GeneralRe: Try/catch block... PinmemberZac Greve27-Nov-12 8:24 
GeneralRe: Try/catch block... PinmemberMember 771191721-Nov-12 9:12 
GeneralRe: Try/catch block... Pinmemberkakan28-Nov-12 0:46 
GeneralRe: Try/catch block... PinmemberPIEBALDconsult20-Nov-12 13:30 
GeneralRe: Try/catch block... Pinmemberjasperp20-Nov-12 20:56 
GeneralRe: Try/catch block... Pinmemberspencepk21-Nov-12 4:03 
GeneralRe: Try/catch block... PinmemberProgramFOX21-Nov-12 4:10 
GeneralRe: Try/catch block... PinmemberRafagaX21-Nov-12 4:28 
GeneralRe: Try/catch block... PinmemberProgramFOX21-Nov-12 4:32 
GeneralRe: Try/catch block... Pinmemberjnlt21-Nov-12 5:33 
GeneralWhy would you do this to a stored procedure? It never did anything to you. Pinmemberthrakazog15-Nov-12 11:58 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. PinmemberZac Greve15-Nov-12 12:48 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. Pinmemberjim lahey20-Nov-12 3:41 
JokeRe: Why would you do this to a stored procedure? It never did anything to you. PinmemberLewis198620-Nov-12 20:50 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. PinprotectorPete O'Hanlon20-Nov-12 12:09 

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
Web02 | 2.8.140721.1 | Last Updated 24 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid