Bad smell ●Hand| e-Bad smell Ignored checked exception public void writeFile(string fileName, String datat Writer writer= null try i / may throw an ioException * writer= new FileWriter(fileName) may throw an IOEXception * writer. write(data) catch(IOEXception e)r/TO Do*/ finally * code for cleanup*/
Bad Smell Handle——Bad Smell: Ignored checked exception public void writeFile(String fileName, String data){ Writer writer = null; try { /* may throw an IOException */ writer = new FileWriter(fileName); /* may throw an IOException */ writer.write(data); } catch (IOException e) ){ /* TO DO */ } finally {/* code for cleanup */} }
● BAD SMELL a checked exception is caught but nothing is done to deal with it the program is pretending that all is fine when in fact something is wrong
BAD SMELL a checked exception is caught but nothing is done to deal with it, the program is pretending that all is fine when in fact something is wrong
Bad smell ●Hand| e-Bad smell ● Dummy handler e public void write File(String fileName, String data) Writer writer null ●●●● try t /may throw an IOEXception * writer new FileWriter(fileName) / may throw an IOEXception * writer.write(data); catch(IOEXception er e print StackTraceO /or System. out. printIn(e to String) finally/* code for cleanup *1
Bad Smell Handle——Bad Smell: Dummy handler public void writeFile(String fileName, String data){ Writer writer = null; try { /* may throw an IOException */ writer = new FileWriter(fileName); /* may throw an IOException */ writer.write(data); } catch (IOException e){ e.printStackTrace(); // or System.out.println(e.toString()); } finally {/* code for cleanup */} }
21 ackage) 230 public void writeFile(String fileName String data)( Library [eclipse] Writer writer noll may throw an IOException * 26 writer=new FileWriter(fileName): g Add throws declaration /* may throw an IOException"/ Pg surround with try/ catch writer= new File Writer(file Name); 3 catch(IoException e)( l/TODO Auto-generated catch block eprintStackTrace 0
e Solution catch(IOEXception e)) throw e:?
Solution catch (IOException e) ){ throw e; } ?