- 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
Wrong, wrong, wrong, all wrong.
"If at first you don't succeed, try and try again. But if you still don't succeed after the third time, give up for the moment, no need to get obsessive about it."
Not sure who said that, some successful entrepreneur of early C20, may have been Ford, may have been Edison. I paraphrased it from memory.
The same can be said for catching errors and exceptions from external resources -- repeat the exercise (after a short delay) in case there's something transient.
Admin
Dedicated attention by a developer to the specific exception handling that will be needed on a project is more likely to direct the developer's attention onto the areas which are likely to throw those exceptions. Hence, because of the resulting greater care and attention, mistakes caused by inadequate problem analysis are less likely to happen.
Having said that, the exceptions that you are most interested in capturing and doing something useful with are those which are outside your direct control: availability of external resources are a case in point. At a particularly primitive level (I know this isn't likely in these current days of commons.io) consider attempting to write a file to a directory. If the directory does not exist it will throw an exception -- but if you catch that specific exception you can direct your application to generate that directory.
The exception structure is there, it's a tool to be used, and it can be misused as egregiously as any other. To those who complain about it, I will call to mind the proverb about bad workmen.
Admin
You don't even understand the word "recursion" do you?
(Clue: there's only one function on the page and recursion is when...what?
Admin
Juste replace public Collection getPersonsInformation(String department,String function) throws LookupException { by public Collection getPersonsInformation(String department,String function) throws LoopUpException {
Admin
java - What is a stack overflow error? - Stack Overflow StackOverflowError (Java Platform SE 7 ) - Oracle Documentation How to solve the java.lang.StackOverflowError | WebRatio StackOverflowError - Adobe ActionScript® 3 (AS3 ) API Reference StackOverflowError | Android Developers Diagnosing and Resolving StackOverflowError - Inspired by Actual ... Bug 53871 – java.lang.StackOverflowError on deploying a web ... etc.
Admin
It's already being logged in that catch, anything after that is gravy.
Admin
If at first you don't succeed, destroy all evidence of the attempt and execute anyone who helped you.
Admin
Admin
I actually agree with you 100%. I use exception handling very rarely, and usually when I didn't write the class that throws the exception. I have written classes that throw exceptions, but only under the rarest of circumstances. 99% of the time I will do exactly what you suggest, return an error and do something else on that return.
Admin
You can have a hierarchical type system without having "OO"... and, your error code approaches are essentially implementing type systems anyway, albeit in a roundabout and limiting way. Just because your language doesn't natively support it doesn't mean you can't create a proper type structure on your own -- all you really need is linked nodes that point to their "superclass" node.
Admin
Plus 1 for that!!!
Admin
With frameworks like .NET, you rarely need to throw exceptions. Maybe when you're creating something that another company will use, and you want to give them something meaningful. You're usually handling the exceptions that the framework throws. They're meant almost to be communication between code layers of different modules. To say things like, "hey dummy! that file that you're trying to read? it doesn't exist!"
Admin
Exceptions are for exceptional circumstances. They may be a language feature but their implementation is by design.
If I designed an object that loaded an entire file into memory I have two choices. Return an error or raise an exception. At the file level inside the object I need to return an error. Outside the object I'm likely to plump for an exception, otherwise you've constructed a useless object for which you need to call a method to see if it failed. Thus, inside the object I see the error & make a choice - raise an exception or not.
The design comes in here. Can I use an existing exception or do I implement my own?
For examples of the latter look no further than Delphi. For implementation problems look no further than raising an exception across threads.
By way of a simple example, if I were to write a 24/7 app I would not be using exceptions whereas if I were using the above mentioned "load all file into memory" object in a twiddly app I wouldn't be concerned if it raised "out of memory", dumped that on the console & stopped.
Admin
We're too dependent upon wheels and gasoline for locomotion nowadays.