Click here to Skip to main content
15,894,343 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: Try/catch block... Pin
Richard Deeming21-Nov-12 2:23
mveRichard Deeming21-Nov-12 2:23 
GeneralRe: Try/catch block... Pin
acomputerdog21-Nov-12 2:27
professionalacomputerdog21-Nov-12 2:27 
GeneralRe: Try/catch block... Pin
Reese Currie21-Nov-12 2:52
Reese Currie21-Nov-12 2:52 
GeneralRe: Try/catch block... Pin
bkebamc21-Nov-12 5:17
bkebamc21-Nov-12 5:17 
GeneralRe: Try/catch block... Pin
H.Brydon21-Nov-12 16:34
professionalH.Brydon21-Nov-12 16:34 
GeneralRe: Try/catch block... Pin
Bernhard Hiller21-Nov-12 20:27
Bernhard Hiller21-Nov-12 20:27 
GeneralRe: Try/catch block... Pin
lukeer22-Nov-12 21:06
lukeer22-Nov-12 21:06 
GeneralRe: Try/catch block... Pin
KP Lee26-Nov-12 7:41
KP 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:
C#
try
{
    int junk = trycat();
}
catch (Exception ex)
{
    Console.WriteLine("caught exception {0}", ex.Message);
    Console.ReadKey();
}

...
C#
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... Pin
Gary R. Wheeler21-Nov-12 4:26
Gary R. Wheeler21-Nov-12 4:26 
GeneralRe: Try/catch block... PinPopular
PhilLenoir21-Nov-12 6:36
professionalPhilLenoir21-Nov-12 6:36 
GeneralRe: Try/catch block... Pin
Brisingr Aerowing27-Nov-12 8:24
professionalBrisingr Aerowing27-Nov-12 8:24 
GeneralRe: Try/catch block... Pin
Member 771191721-Nov-12 9:12
Member 771191721-Nov-12 9:12 
GeneralRe: Try/catch block... Pin
kakan28-Nov-12 0:46
professionalkakan28-Nov-12 0:46 
GeneralRe: Try/catch block... Pin
PIEBALDconsult20-Nov-12 13:30
mvePIEBALDconsult20-Nov-12 13:30 
GeneralRe: Try/catch block... PinPopular
jasperp20-Nov-12 20:56
professionaljasperp20-Nov-12 20:56 
GeneralRe: Try/catch block... Pin
spencepk21-Nov-12 4:03
spencepk21-Nov-12 4:03 
GeneralRe: Try/catch block... Pin
Thomas Daniels21-Nov-12 4:10
mentorThomas Daniels21-Nov-12 4:10 
GeneralRe: Try/catch block... Pin
RafagaX21-Nov-12 4:28
professionalRafagaX21-Nov-12 4:28 
GeneralRe: Try/catch block... Pin
Thomas Daniels21-Nov-12 4:32
mentorThomas Daniels21-Nov-12 4:32 
GeneralRe: Try/catch block... Pin
jnlt21-Nov-12 5:33
jnlt21-Nov-12 5:33 
GeneralWhy would you do this to a stored procedure? It never did anything to you. PinPopular
thrakazog15-Nov-12 11:58
thrakazog15-Nov-12 11:58 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. Pin
Brisingr Aerowing15-Nov-12 12:48
professionalBrisingr Aerowing15-Nov-12 12:48 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. PinPopular
jim lahey20-Nov-12 3:41
jim lahey20-Nov-12 3:41 
JokeRe: Why would you do this to a stored procedure? It never did anything to you. Pin
Lewis198620-Nov-12 20:50
professionalLewis198620-Nov-12 20:50 
GeneralRe: Why would you do this to a stored procedure? It never did anything to you. PinPopular
Pete O'Hanlon20-Nov-12 12:09
mvePete O'Hanlon20-Nov-12 12:09 

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.