Click here to Skip to main content
15,898,036 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.

 
GeneralMessage Closed Pin
5-Jul-10 8:13
_beauw_5-Jul-10 8:13 
GeneralRe: try-catch code convention Pin
Eddy Vluggen6-Jul-10 7:27
professionalEddy Vluggen6-Jul-10 7:27 
GeneralMessage Closed Pin
14-Jul-10 13:05
_beauw_14-Jul-10 13:05 
GeneralRe: try-catch code convention Pin
Eddy Vluggen14-Jul-10 20:43
professionalEddy Vluggen14-Jul-10 20:43 
GeneralRe: try-catch code convention Pin
Kunal Chowdhury «IN»5-Jul-10 23:34
professionalKunal Chowdhury «IN»5-Jul-10 23:34 
GeneralRe: try-catch code convention Pin
fjdiewornncalwe6-Jul-10 4:41
professionalfjdiewornncalwe6-Jul-10 4:41 
GeneralRe: try-catch code convention Pin
Abhinav S6-Jul-10 19:04
Abhinav S6-Jul-10 19:04 
GeneralRe: try-catch code convention Pin
Alois Kraus15-Jul-10 22:22
Alois Kraus15-Jul-10 22:22 
Sounds familar Smile | :)

Perhaps you should add at least some tracing to your methods like this one

Then your code would be transparent to exceptions but you can still see what exceptions did flow through your code without becoming much slower.

public void Demo_Show_Leaving_Trace_With_Exception()
{
    TracerConfig.Reset("console");
    SomeMethod();
}

void SomeMethod()
{
    using (Tracer t = new Tracer(myType, "SomeMethod"))
    {
        SomeOtherMethod();
    }
}

private void SomeOtherMethod()
{
    using (Tracer t = new Tracer(myType, "SomeOtherMethod"))
    {
        FaultyMethod();
    }
}

private void FaultyMethod()
{
    throw new NotImplementedException("Hi this a fault");
}


The output would look the like this:
18:57:46.665 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod
18:57:46.668 03064/05180 <{{ > ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Exception thrown: System.NotImplementedException: Hi this a fault
at ApiChange.IntegrationTests.Diagnostics.TracingTests.FaultyMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod()
at ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception()
18:57:46.670 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod Duration 2ms
18:57:46.689 03064/05180 < }}< ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod Duration 24ms

That is a great time saver to find out where some exception did come from without the need to type try/catch(Exception ex) { LogException(ex);throw; } in many methods to find out where some exception did go through.

Yours,
Alois Kraus
GeneralRe: try-catch code convention Pin
whatrevolution19-Jul-10 4:03
whatrevolution19-Jul-10 4:03 
GeneralRe: try-catch code convention Pin
Hired Mind22-Jul-10 7:19
Hired Mind22-Jul-10 7:19 
GeneralMy turn on MS Bashing PinPopular
peterchen1-Jul-10 0:59
peterchen1-Jul-10 0:59 
GeneralA whole day wasted on one stored procedure Pin
ChrisC(@ncmail)28-Jun-10 12:29
ChrisC(@ncmail)28-Jun-10 12:29 
GeneralRe: A whole day wasted on one stored procedure Pin
J4amieC28-Jun-10 21:59
J4amieC28-Jun-10 21:59 
GeneralRe: A whole day wasted on one stored procedure Pin
David Skelly28-Jun-10 22:36
David Skelly28-Jun-10 22:36 
GeneralRe: A whole day wasted on one stored procedure Pin
ChrisC(@ncmail)29-Jun-10 8:16
ChrisC(@ncmail)29-Jun-10 8:16 
GeneralRe: A whole day wasted on one stored procedure Pin
PIEBALDconsult9-Jul-10 10:47
mvePIEBALDconsult9-Jul-10 10:47 
GeneralStupid Naming Consequences with LINQ Pin
Member 269131324-Jun-10 22:45
Member 269131324-Jun-10 22:45 
GeneralRe: Stupid Naming Consequences with LINQ Pin
whatrevolution25-Jun-10 2:49
whatrevolution25-Jun-10 2:49 
GeneralRe: Stupid Naming Consequences with LINQ Pin
User 274316225-Jun-10 23:59
User 274316225-Jun-10 23:59 
GeneralMessage Closed Pin
28-Jun-10 8:59
_beauw_28-Jun-10 8:59 
GeneralRe: Stupid Naming Consequences with LINQ Pin
David Skelly28-Jun-10 22:38
David Skelly28-Jun-10 22:38 
GeneralRe: Stupid Naming Consequences with LINQ Pin
whatrevolution3-Jul-10 17:28
whatrevolution3-Jul-10 17:28 
GeneralRe: Stupid Naming Consequences with LINQ Pin
Hired Mind13-Jul-10 10:00
Hired Mind13-Jul-10 10:00 
GeneralRe: Stupid Naming Consequences with LINQ Pin
Marcelo Ricardo de Oliveira8-Jul-10 6:50
Marcelo Ricardo de Oliveira8-Jul-10 6:50 
GeneralJavaScript Conditional Pin
Andres Martin23-Jun-10 12:05
Andres Martin23-Jun-10 12:05 

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.