Path: csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 06 Jul 2013 07:43:46 -0500 Date: Sat, 06 Jul 2013 13:43:44 +0100 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: About java program. References: <324f929f-772e-4004-81e1-6b454cdae794@googlegroups.com> <19wnriq53qxel.u9rt8wy6z52g.dlg@40tude.net> <1lvu4yv8sxe73$.n4o05ixuag9y.dlg@40tude.net> <85GdncWZdo04-lzMnZ2dnUVZ8mydnZ2d@bt.com> <51d6396c$0$295$14726298@news.sunsite.dk> <51d77b0d$0$290$14726298@news.sunsite.dk> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 104 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-UHoqeCsYPHsm4qxWN97cMZNuGnDyw/xL0UL/2BmJUDEsYdO7aKHqcs9bt3P4n9JnZYGE5lvX1n4QtEG!CesEjXWKlW5+8hyOFpq5EfkZcK3Mq8QTx8gvupa9QIL9YYHd4alWHUmBeSPsPEH8MP8wdwqqPK0= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 6004 Xref: csiph.com comp.lang.java.programmer:24679 On 06/07/13 12:01, Robert Klemme wrote: > On 06.07.2013 04:03, Arne Vajhøj wrote: >> On 7/5/2013 5:15 PM, Robert Klemme wrote: >>> On 05.07.2013 10:13, lipska the kat wrote: >>>> private boolean askYesNoquestion (String str) throws >>>> BadArgumentException{ >>>> >>>> boolean result = false; >>>> >>>> if(null == str){ >>>> logger.log("Argument is null"); >>>> throw new BadArgumentException("Argument is null"); >>>> } >>>> else{ >>>> if(str.equals("yes")){ >>>> result = true; >>>> } >>>> else if(!str.equals("no")){ >>>> logger.log("Incorrect Argument, argument is " + str); >>>> throw new BadArgumentException("argument is " + str); >>>> } >>>> } >>>> return result; >>>> } >>>> >>>> This is *one* way of doing it >>>> >>>> Overkill ... no, defensive yes. >>> >>> This example demonstrates what I will call bad practice: the exception >>> is thrown so the calling code can decide how to handle the error. It >>> may actually be that the caller can perfectly deal with that situation >>> and proceed normally. Method askYesNoquestion() cannot know this. But >>> because the method does the logging itself you'll end up seeing messages >>> in a log file for things which are not noteworthy. I say, either log >>> and deal with the error locally OR throw an exception containing a >>> meaningful message - but not both. That is misleading. >> >> I do not agree with the last point. >> >> If we look at the matrix: >> >> caller logs caller do not log >> log insignificant extra log entry fine > > I do not agree to the "insignificant". > >> not log fine big problem troubleshooting >> >> then it seems obvious to me to log anyway. Worst case by logging >> is not nearly as bad as worst case not logging. > > Maybe I haven't made myself clear enough: it is the task of the writer > of the calling code to decide whether the exception is a problem or not. > This decision cannot be done by the author of this method. The author has determined that certain conditions are exceptional Who else but the author is qualified to make such a decision? It's not up to caller "to decide whether the exception is a problem or not" If there was no problem then there would be no exception. It's up to the client to decide how to handle it ... a situation over which the original author has no control. And this is the point, If I write a method that will be used by others outside my sphere of influence and that method throws an exception then as the author I would want to know what was going on, I sure as hell wouldn't look hopefully towards the client to see if they know why my black box component was throwing an exception. They would expect to see some logging ... I would too in the same situation. > Presumably > this is a low level method which is invoked from many different places > and so some may be able to handle the exception while some may not. > Since a RuntimeException (NPE is one) will be likely caught somewhere > high up the call chain and logged there (usually with the stack trace) > debugging should not be too difficult. If on the other hand you need to > wade through tons of log messages which do not signal an error Show me where I log anything that is not an error. if the argument is null that is an error. Log the error at the point of origin. Inform the client by throwing an exception if the argument is yes then no logging occurs and the result is set to true if the argument is no then no logging occurs, the default is returned If the result is not yes or no and it's not null then that is an error Log the error at the point of origin. Inform the client by throwing an exception. > then debugging is also harmed. Not to mention the additional IO overhead for > all the superfluous log messages. There is no such thing IME, any decent logging framework is configurable by level. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun