Click here to Skip to main content
15,867,568 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: .Net Core 6 jumps the shark Pin
MSBassSinger4-Dec-21 13:56
professionalMSBassSinger4-Dec-21 13:56 
GeneralRe: .Net Core 6 jumps the shark Pin
Jon McKee4-Dec-21 14:21
professionalJon McKee4-Dec-21 14:21 
GeneralRe: .Net Core 6 jumps the shark Pin
MSBassSinger4-Dec-21 15:00
professionalMSBassSinger4-Dec-21 15:00 
GeneralRe: .Net Core 6 jumps the shark Pin
Jon McKee4-Dec-21 16:12
professionalJon McKee4-Dec-21 16:12 
GeneralRe: .Net Core 6 jumps the shark Pin
Richard Deeming5-Dec-21 22:00
mveRichard Deeming5-Dec-21 22:00 
GeneralRe: .Net Core 6 jumps the shark Pin
MSBassSinger7-Dec-21 8:53
professionalMSBassSinger7-Dec-21 8:53 
GeneralRe: .Net Core 6 jumps the shark Pin
Richard Deeming7-Dec-21 22:10
mveRichard Deeming7-Dec-21 22:10 
GeneralRe: .Net Core 6 jumps the shark Pin
MSBassSinger8-Dec-21 5:17
professionalMSBassSinger8-Dec-21 5:17 
I am sorry you do not fully understand what I wrote.

First, I did show that constructor exceptions are "swallowed", though I do admit that is a subjective term. To be more precise, constructor exceptions occur outside the MSIL exception handling. In order to catch the constructor exception, the "using" has to be wrapped in a try-catch of its own.

Second, because of what I just explained, the unit test that implements "using" needs the outer try-catch, while the other approach does not. The "using" approach results in nested try-catches, which is why it creates more lines of code to be executed. The coding for the unit tests is correct "as-is". The outer try-catch in your version of the StandardUsageTest() method is unnecessary.

Third, the execution time is not the point. I ran them several times, to account for any caching, and the time relationship remains the same. The point is that a very popular C# coding shortcut results in more lines of code to be executed (MSIL) than the other approach, and forecloses the opportunity to capture runtime values in the exception's Data dictionary within the MSIL code.

If you want to stick with the "using" statement, then do so. I am not trying to tell you or anyone else what they should do. I am presenting information for the "what" and "how" so that an objective person can decide for themselves. I provided the details, as was asked, and it completely and rationally supports my thesis. If you agree, fine. If you disagree with rational reasons you can explain, then educate us all. But since you are disagreeing without a rational basis, that is fine. You should continue to do things the way you think is best. But if you don't like my approach, just admit it is a personal preference to stick with the "using" statement. For example, if benefitting from more advanced exception handling does not provide a value for you, then implementing the "using" statement makes sense.
GeneralRe: .Net Core 6 jumps the shark Pin
Richard Deeming8-Dec-21 6:18
mveRichard Deeming8-Dec-21 6:18 
GeneralRe: .Net Core 6 jumps the shark Pin
PIEBALDconsult11-Dec-21 8:50
mvePIEBALDconsult11-Dec-21 8:50 
GeneralRe: .Net Core 6 jumps the shark Pin
zezba900029-Nov-21 9:35
zezba900029-Nov-21 9:35 
GeneralRe: .Net Core 6 jumps the shark Pin
PIEBALDconsult11-Dec-21 8:42
mvePIEBALDconsult11-Dec-21 8:42 
GeneralWhat the heck are they teaching philosophers in Florida? Pin
honey the codewitch28-Nov-21 5:54
mvahoney the codewitch28-Nov-21 5:54 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
trønderen28-Nov-21 6:04
trønderen28-Nov-21 6:04 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
honey the codewitch28-Nov-21 6:05
mvahoney the codewitch28-Nov-21 6:05 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
honey the codewitch28-Nov-21 6:08
mvahoney the codewitch28-Nov-21 6:08 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
Daniel Pfeffer28-Nov-21 21:37
professionalDaniel Pfeffer28-Nov-21 21:37 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
Greg Utas28-Nov-21 6:06
professionalGreg Utas28-Nov-21 6:06 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
honey the codewitch28-Nov-21 6:06
mvahoney the codewitch28-Nov-21 6:06 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
Greg Utas28-Nov-21 6:49
professionalGreg Utas28-Nov-21 6:49 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
honey the codewitch28-Nov-21 6:50
mvahoney the codewitch28-Nov-21 6:50 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
Greg Utas28-Nov-21 6:53
professionalGreg Utas28-Nov-21 6:53 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
Marc Clifton28-Nov-21 7:01
mvaMarc Clifton28-Nov-21 7:01 
GeneralIt is called a Doctorate of Philosophy because... Pin
Michael Breeden29-Nov-21 1:04
Michael Breeden29-Nov-21 1:04 
GeneralRe: What the heck are they teaching philosophers in Florida? Pin
obermd29-Nov-21 6:39
obermd29-Nov-21 6:39 

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.