Kristopher Micinski wrote: > > Lew <lewb...@gmail.com> wrote: > >> >> Kristopher Micinski wrote: >> >>> > BelvCompSvs wrote: >>> >>>> I'm just here to confirm what the other two coders told you ~ I >>> found >>> >>>> it on first read place a catch( Throwable ) around the call >>> >>>> to .print_result(MyService. >>> >>> >>> >>> That's actually pretty bad advice. Don't place a 'catch (Throwable >>> >>> ...)' >>> >> > around anything. >>> >> > >>> >> >>> >> Ever? >>> > >>> > That is a good question. >>> > I suggest asking it each time the situation comes up. >>> >>> There are 'correct' uses of try / catch blocks, and exceptions in the >>> Java language. You might be able to get away with avoiding using them in >>> your own code, but the standard library throws things, so you can't >>> completely avoid ignoring them. >>> >>> If you want to enforce a coding standard which eschews them, that's >>> fine, but I don't think it makes sense (otherwise) to make a blanket >>> statement against their use. >>> >>> >> OK, and who was making a blanket statement against the use of exceptions? >> >> > Sorry, Lew, I wasn't clear on this one, and I agree that your statement > doesn't come off as "blanket against exceptions" as I implied. >
I didn't even make a statement about exceptions, much less against them, much less a blanket statement against them. > However, there are uses of catch throwables that aren't completely > harmful, as you can rethrow after handling. Although yes, you shouldn't > use them for swallowing up exceptions.. > There are many 'Throwable's that you cannot handle, so you shouldn't really catch them. Usually. 'Throwable" itself is a prime example. Similarly it's usually pretty useless to try to "handle" an 'Eror'. Beyond all that, exception handling is supposed to be a deft tool, not a blunt one. Don't just 'catch(Exception exc)'. It's even worse to 'catch(Throwable thr)'. Apparently you missed that I am talking specifically about the type 'Throwable', hence the care with case and placement within apostrophes. The problem is the lack of precision in such a catch - it shows that the programmer really didn't understand or bother to think about what sort of things might throw. I do not advise ignoring exceptions, as you so royally misconstrued, but the exact opposite. I urge programmers to catch precisely the exceptions that one should catch. Don't just sloppily catch the catch-all 'Exception' or 'Throwable'. Furthermore, my original comment was specific to the OP's circumstance, and not in any way a blanket statement. I made it in response to advice to 'catch(Throwable ...)' that was made without any understanding of what was actually wrong in the OP's code or of the appropriate fix for it. Regardless, it is generally true that one should avoid catching 'Throwable', any 'Error' subtype or the top-level 'Exception' type. 'Throwable' and the subtypes of 'Error' typically are too severe even to count on being able to log the problem. ('AssertionError' is a notable exception.) Catching 'Exception' is just sloppy, but for the catch-all use case at a top level of the application. Note that by "generally true" I mean "as a general rule", i.e., "not necessarily universally true but at least nearly so". It is universally true that 'try'-'catch' and exception handling are a powerful and useful technique, as you averred. -- Lew -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en