Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CodeSOD: Universal Catch

Computers were a mistake, which is why I'm trying to shoot them into space. Editor-in-Chief for TDWTF.A common pattern is "global Error handlers"- functions you call in your catch block that do some task, usually logging, when an exception occurs. Given that exception handling frequently involves a fair bit of repeated code, centralizing that isn't a terrible idea. So when Magnus found code like this in the codebase, he didn't think much of it:I can't say I love the naming conventions, but it's a pretty straight forward C# Linq method, projecting and sorting data. I don't think that the ToList should be there, because we could be leveraging lazy evaluation (or maybe we shouldn't, I don't know their access patterns, but at a guess, lazy would be better here). Anything goes wrong, we pass the error to our global exception handler.This exception handler was called everywhere. So what did it do?Oh, nothing. It does (basically) nothing. Presumably, once upon a time, this was meant to be an error handling framework that they'd hang a lot of functionality off of- but that never happened. This was their production code, and this was their error handling solution.Copyright © 2023 Inedo Publishing - v2023.2Monitored by Panopta • Deployed with BuildMaster



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

CodeSOD: Universal Catch

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×