- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Potential for Exceptionceptioneoption?
Admin
I'll just leave this here...
https://msdn.microsoft.com/en-us/library/System.ApplicationException
And this...
http://stackoverflow.com/a/5685943/1386111
Admin
No, but the exception you throw might not be the exception you expected to throw. Because.
Admin
Well you only need to overload the SendEmail function (I am not at all familiar with .net, so bear with me) with a custom one which do use your own mandatory exception(inception) class..... Booom :smile:
Admin
An exceptional display in FF 40.0.3:
[image]No problems in IE11 though; anyone else seeing this?
Edit: Damnit - Ignore this, the problem was due to cr*ppy FF cache handling. Post not deleted to retain context for @RFoxmich's response.
Admin
http://pre04.deviantart.net/d429/th/pre/f/2013/163/5/9/ring2_by_badriel-d68re7u.png
Throw it into the fiery depths of the crack of doom.
Admin
So you make sure that at least the error is logged, even if the application blows up or silently swallows the exception. Not a real :wtf: IMHO.
Admin
Why are you stuffing a ring in someones butt crack?
Admin
Thank you Remy, exceptional article.
Admin
I have an almost identical setup and class except it logs rather than sending emails.
The origin of that was that there were several modules that could be pieced together in a variety of ways that would encounter various error conditions and would eventually output to a variety of frontends.
Certain error states would preferably cause a variety of different behaviours once caught at the top. With some potentially deep call stacks the only convenient way to send error information back up to a scope that can handle it is to use custom exceptions. Anything else would require the use of globals/parent variables or special return types which would mean modifications to every method/class in the call trace up to the original caller. I have seen these kind of solutions in practice and they always cause more harm than good.
In some cases this could have been avoided with checks earlier on if it were not a legacy codebase and in other cases this was more complicated. The problem was that this was not a library written entirely from the ground up but rather had to integrate into a pre-existing codebase. The exceptions were hacked onto it as an afterthought to make libraries more portable. The time constraints, program flow design and other aspects of the legacy codebase made it difficult to implement proper handlers. The net result of this was that rather than having an exception type that would imply the action to take once it reached the top most handler would be to log it, the class would log errors in the constructor. The other solution is to use the publisher-subscriber pattern but that doesn't solve the problem with return types that exceptions are meant to solve. When it comes to exceptions even with good handling you can still have a lot of bootstrap problems. The base structure of the code has to be designed to handle this.
This is something I considered refactoring but as it actually works really well apart from some implementation ugliness it's a bit of a case of YAGNI or don't fix what isn't broken. Ultimately the reason it is like that is because of the structure of the rest of the code in the application so it's a case of if you fix this, you have to fix everything which means a full rewrite.
Normally if you see this anti-pattern, it is because it wasn't practical to put the handling anywhere else. The WTF for me is that this was written presumably from scratch as a standalone library. That leaves little excuse for not providing handlers with the exceptions.
Admin
A while back they made a cleanup pass through Windows XP. They found a very similar situation, where some low-level code in the kernel was calling up to do some HTTP stuff, like a dozen levels above that layer.
Admin
At least it was photographed on a wooden table :^)
Admin
Sometimes, as developers, we're forced to do things we're not proud of due to ridiculous time constraints or arbitrary requirements handed down from people who have no clue as to what they are really asking for. That said, they should have done a few things differently:
Admin
I'm not sure how much I agree. At first glance in principle it looks valid but then the real world strikes...
The worst possible thing that could happen is if SendEmail somehow triggered another BaseException, after sending the email. That's the one that wants to behave like a singleton. Some people improve this by sending the encrypted error as output (youtube).
Admin
:rofl: Ever the optimist, huh? Even comments like
// DO NOT EVER FUCKING DO THIS!!!
won't deter the truly incompetent.Admin
"Don't forget to quote from our institute library in your thesis - what for would we have it otherwise? And make sure you quote from every single one of the 63,187 books."
Admin
Admin
Yep exactly.
That is why I only do logging/emailing of errors in the catch, there you are (a bit at least) sure that things will not get much worse if the logging/emailing system goes belly up...
Admin
"aggressively incompetent"
Admin
Crudfully? Really? What, was your mom sitting over your shoulder when you typed this email? And is your mom the kind of lady that won't let you type the word 'crap'? Don't get me wrong, I still woulda made fun of you if you had typed 'crapfully', I prolly would have just left your moms out of it.
Admin
I thought it was clear and obvious that I was actually referring to this.
Filed under: Next time I'll post a link.
Admin
Definitely a Few WTF's in the implementation. But the concept of having a logging point at the creation of the exception is potentially reasonable, if not ideal.
Most developers [that program in .NET and use Visual Studio - all others can ignore the technobabble] have at some point used Debug->Exceptions and enabled "Break on Throw" rather than (the default) "Break on Un-Caught" to get further insight.
Now if we look at the lifecycle there is...
Writing logging code for #3 is trivial (and the most common). Fewer than 10% (based on many interviews given) of Senior developers know that #2 and #4 can be done - even fewer know how; only ONE developer interviewed for a "regular" position has gotten this right in a decade!
So it is natural that there is a focus by many to resort to #1. The real fun start when you then find...
The logging occurs even if the exception is NOT thrown....
Admin
Nevermind Ben. He just got old enough to be allowed to use foul language.
Admin
I'm aware of that but it is not what he advertised it for. I'm sceptical loading configuration would fail that often and that is more of a monkey patch than a real solution. The biggest WTFs are when such systems are continually monkey patched rather than taken back to the drawing board. The email handling is a far bigger problem. It's a mailbomb waiting to go off.
Admin
If you were going to go back and refactor this, I would definitely recommend doing things differently than this implementation. I can think of several ways to accomplish this same thing that don't involve sending emails from a class constructor ::shudder::
Admin
You could send it from the
Finalize
method… :tropical_fish:Admin
I think you're still better off building some static class that contains a static method that accepts the exception as an argument. Then, anywhere you want an email sent, you just add the method call to the catch, passing the exception. That method then formats and sends your email, with its own error handling and secondary logging mechanism in case it's not able to send the email. Then, it's just a matter of getting enough people with a basic understanding of syntax and the ability to use Copy/Paste to add in those calls. For any exceptions that don't have a Try/Catch, there's the Global.asax, or Application.OnUnhandled (I think that's the method name. Haven't done WinForms apps in a while)
Admin
Surely what you do is you pass a lambda (or whatever the right C# name for those things is) to the method which calls the function and then traps any problems and sends emails and logs them in databases and so on. Easy!<in a Doing It Wrong way that is
Admin
I just remembered: you mentioned the "mail bomb". I have for years run code that will send email notifications for applications. Much the setup I described here: https://what.thedailywtf.com/t/taking-exception/51251/29
I can trigger emails from inside a Catch block, but I also have it set to notify me of all unhandled exceptions via the global.asax. Often, I know when the SQL or GIS box is offline (or having problems) before the network guys do. I also get notified when "weird" requests come in, or 404 errors get thrown. Sometimes that can get annoying, but I use exchange rules to manage most of it.
A couple of years back, I was working for a company that did paperwork processing for banks. I'm sitting at home one night (about 9pm), playing Xbox, when I glance down at my trusty (not really) Blackberry Bold and notice that I have over 7000 new emails. My first thought was to laugh and wonder what kind of drugs my Blackberry was smoking this time. Then I noticed the number was increasing. Rapidly. The Blackberry was so busy downloading emails, I could barely get it to respond. So, I fired up the VPN and connected to my workstation at the office. That's when I saw my inbox: over 37,000 new emails and counting.
I looked at a couple of them, and it was obviously someone trying to find a querystring or SQL injection vulnerability in the site. I tried calling my boss, but got no answer, so I immediately started typing an email to my boss, and every person I know of in the network team. In the middle of typing, I got disconnected from my workstation. Kept trying to get back in, but it just kept telling me that there was no response.
So now I'm really starting to freak out, thinking that someone had actually gotten in. I managed to type up an SMS message on my Blackberry to my boss that just said "Hackers in server. Phone not working. Call my personal cell." No response.
The next morning, I walked in the door and headed straight for my bosses office. I found out that one of our customers had decided to run an intrusion test suite against the site during the night. I had ended up with over 45,000 new emails. I asked them to let me know if future, so that I could disable the email notification system in the web.config.
But nobody had any idea why I had been kicked out of my workstation during the middle of it all.
I found out later that one of the pieces of software that the accounting team used only allowed a single user to be in the system at a time. Apparently, their MO when someone was in the office by themselves and couldn't get in was to go around and hold the power button on every other PC in accounting, powering them down. That night, one of the accountants had simply gone one cubical too far down and happened to power down my PC right at that moment.
There's probably a few RWTF's in there ;)
Admin
This, kind entities, is why I never walk away from my PC without saving everything. Also why I unplugged the power LED cable from the motherboard.
Admin
Admin
Ok, now you got me interested even though I'm looking in from Java...
Number 4 seems to be done by registering an event handler on a special delegate (e.g. http://www.codeproject.com/Articles/2949/Managing-Unhandled-Exceptions-in-NET) which you can do thread-by-thread in Java as well, but number 2 is something I've never seen being done in Java.
My Google-fu indicates that it can be done using the AppDomain.FirstChanceException event, does it work all that well?
Admin
You might have to use an AOP interceptor. Ugly.
Admin
Huh. I thought Googling for "log all unhandled exceptions" would cover at least #4.
Didn't know you can also hook to first-chance, but that seems to be of pretty little use - a caught exception might be a nigh-fatal error, a simple condition, or even a part of normal program operation (say, you have something that needs custom parsing and the library doesn't expose
TryParse
).Admin
Try checking the "break on first-chance" checkbox in VS and see how much time you need for it to get on your nerves. The estimate is about 20 to 30 minutes, possibly less depending on the libraries used.
Point is, it's useful when you know what you're looking for (say, a library gives you a nondescript "An error has occured" ThatLibraryException, and you try to investigate), and totally annoying otherwise.
Admin
Ding Ding Ding we have a winner.
Admin
Not in Visual Studio....when your code is running in production.
Admin
If it's a metal power button, figuring out a way to attach it to a high-voltage input line would also prevent hostile entities from attempting to press it. More than once.
Admin
Oh that's easy, just reverse ground and live. Most cases have rubber feet, right?