From: <we...@in...> - 2003-02-06 10:17:46
|
Hello Stefan, just an idea/comment !;-) If Exceptions are used; every other method calling this method must have a try/catch-block which is a lot of work and slows down the processing time because simple return values would be faster. I want only to bear that in mind ! I think a simple return Double.NaN should work and every calling function can check this by double hose=predict(hcode); if(Double.isNaN(hose)) { logger.error(...) // or throw CDKException("Hose code "+hcode+" doesn't exist.") // or forward NaN return hose; } else { // all is fine } C is not that bad and to return a register value will be always faster than returning a thread based Exception. Regards, Joerg > in general i think: > - Exception should only be used if some weird things happening and > there is no developer possibility to avoid this, e.g. NullPointer, > NumberFormat, IO > - they should not be to specific, because this causes overhead > - they are usefull, if different exceptions can occure and the > developer wants to catch only a specific kind of exception. > BUT it's not a good idea to use Exception in general as return > value of methods if something weird is happening. Often a simple > true/false will work. If the why 'failed this method' is important > there exists still the logging with different modes. > > > Hi Joerg, > what you say sounds reasonable, but for me it seems to be more C rather than > Java style. Take the BremserBlaBla methods: > > public double predict(String hoseCode) throws CDKException > { > if (ht.containsKey(hoseCode)) > { > return ((HOSECodeShiftRange)ht.get(hoseCode)).shift; > } > throw new CDKException("No such HOSE code"); > > The return type to indicate a failure would be, I suppose, a negative value > like -1. But this would be contrary to what you read in all the java books > and also to my own feeling (although I got that from the books, I admit). So > I think some sort of exception would be better. > Stefan > -- Dipl. Chem. Joerg K. Wegner Univ. Tuebingen, Computer Architecture, Sand 1, D-72076 Tuebingen, Germany Tel. (+49/0) 7071 29 78970, Fax (+49/0) 7071 29 5091 E-Mail: mailto:we...@in... WWW: http://www-ra.informatik.uni-tuebingen.de |