jane bailey jane bailey is a self-published author of urban fantasy novels as well as a part-time blogger; in her day job, she works in sqa, where she sees plenty of wtfs. 




enterprise resource planning software, or erp for short, is crucial to the operation of many large businesses. several popular erp systems have plugin-friendly architecture, the better to sell upgrades their customers will never want or use. this software is primarily aimed at businesses with too many complex process flows to manage by hand<u+2014>making it the perfect domain for a small, lean startup with 3 developers and 1 customer. 




ethan and roland were brand-new developers, fresh out of college and ready to take on the world. patrick, a consultant, was more experienced, though still fairly early in his career. they worked in c# with the visual studio ecosystem, and their boss had bestowed just one instruction as to how their culture should be formed: 




"picture a scale from 1 to 10, with 1 being fast and 10 being scalability and code quality and all that crap. i want you to aim for a 2." 




visual studio is a great tool for beginning developers who need to work fast. it makes scaffolding the code simple and efficient, and allows for a drag-and-drop visual design that lets you rapidly prototype your screens. couple that with great intellisense, and the team was confident they could deliver their addon as promised. 




that said, visual studio is also a complex piece of software, with many of its best features hidden inside a labyrinthine menu system and/or optional settings deep in a configuration file. it works better if you have time to learn how to use it. unfortunately, our erp team did not have that kind of time, and they missed a few key features. for example, out of the box, visual studio won't step into a catch block while debugging. you can debug catch blocks, but you have to explicitly set a breakpoint in them or they will be skipped entirely. there's an option to turn this behavior off, but it's hidden deep in the menus. 




ethan and roland developed a workaround for this behavior that let them continue working: they would comment out catch blocks surrounding code they were actively debugging, then restore the commented-out code afterward. but this took time and effort, and often multiple cuss-filled executions as they realized the exception was handled at a higher or lower level than they'd originally anticipated and they had to comment out more code. finally, patrick came up with a more creative solution: pre-emptively comment out all try-catch blocks in the entire solution, and stop adding more. 




"there's no time for exception handling," he scoffed. "we have to move fast or we won't hit our street date." 




ethan was concerned by this solution. he'd already caught himself forgetting to un-comment catch blocks using their old strategy. wasn't this infinitely more risky? and how would they know their catch blocks were written correctly? what about testing the error messages they were meant to display to the users? still, he was brand new, and patrick had industry experience, so he was overruled. 




the weeks wore on, and development moved at blazing speed. the developers did their own unit tests, and from time to time, their ba would perform manual tests of the addon installed in the erp system. it mostly crashed, but it was early yet. there was time to figure it out. still, blazing isn't quite lightspeed, and the ba kept finding more and more crucial functionality that would be required if anyone was going to be interested in purchasing the thing. the general feeling of the project team matched the immortal words of sonic the hedgehog: "we're not going to make it. let's speed up!" 




the team took on more developers in an effort to increase overall velocity. one of these was alex, a contractor with 30 years of experience handling it projects. alex rapidly emerged as the clear leader of the entire team; his age and experience dethroned even patrick. he spent increasing amounts of time sequestered with the boss, talking through everything from planned features to plugin architecture to the speed of development, which the boss felt was responsible for their missed milestones. not because the code quality was crappy and therefore more time was spent fixing bugs, but because developers "weren't coding fast enough." 




the codebase had grown from a few hundred lines to several thousand. ethan had found the magic toggle for visual studio that made it step into catch blocks, much to his relief. he reported this to the boss, and the ban on exception handling was (begrudgingly) lifted. ethan adjusted rapidly, but many of the other developers still blamed exception handling for the slowness of coding. often the addon would crash due to an incorrect cast or bad index. however, handling exceptions was seen as wasted time, so many developers refused to do it. 




upon overhearing the boss and alex discussing the matter, ethan threw in his two cents. "we're nearing release. we should really start adding exception handling to all new code. then we should do a final round of testing to make sure nothing breaks." 




this didn't go over well with the boss. the solution was simple to him. "just don't use any exception handling. remove all of it. then we won't have to test anything extra, and we might even make our deadline." 




ethan, after retrieving his jaw from the floor, protested violently. "who's gonna pay for a system that crashes the moment you look at it wrong? what about data integrity? if bad data is persisted to the database, it'll fill up with garbage<u+2014>and then the application will throw even more exceptions!" 




"i know it's not ideal," said the boss, "but there's no time. remember the scale: we need to be at a 2, and you're at like a 6 right now. this is industry standard stuff. trust me on this, okay?" 




time marched on. the company doubled in size, adding more developers who were forbidden from using exception handling. they moved even faster now, approaching the final ship date<u+2014>well, the new final ship date, anyway. 




one day, while debugging, ethan noticed that the addon didn't crash anymore, but did log an error to the console. "wait, what? where was that handled?" 




concerned, he dug through the code. most of his exception handling had been removed or commented out; he couldn't find a single catch block in the whole module he was working on. finally, he found it: at the very top level, someone had put a try-catch block around the entry point to swallow any exceptions that were thrown. 




ethan asked alex about it the next time he caught him in the hallway. 




"yeah, we can't have the addon crashing all the time, you know?" alex shrugged. 




another junior developer poked his head out of a nearby cubicle. "it turns out, in c#, if you have an exception, the entire application crashes! crazy, right? i found that out last week, and i told alex about it, so we decided to implement exception handling." 




ethan had no words at first. he just cradled his forehead in the palm of his hand. finally, he tried one last time to explain. "look. exception handling is a good idea. but this is going to swallow all the errors, so debugging will be impossible. at the very least, let's put a catch block around each module so we know which one failed. and stop removing my catch blocks!" 




alex shook his head. "you just have to do it right. all of you," he added, raising his voice so the others could hear. "if you just code it right from the start, there won't be exceptions, and handling them won't be necessary!" 




ethan learned a valuable lesson that day: why exactly it was that startup developers tended to congregate in bars and debate the merits of various fine liquors online. it wasn't that people who liked alcohol were drawn to software development. working at places like this drove developers to drink. [advertisement] universal package manager - proget easily integrates with your favorite continuous integration and build tools, acting as the central hub to all your essential components. learn more today!
exceptional handling
jane bailey