Refactoring ● Refactoring: Replace ignored checked exception with unchecked exception o Replace dummy handler with rethrow o wrap the checked exception into an unchecked UnhandledEXception o Throw UnhandledException
Refactoring Refactoring: Replace ignored checked exception with unchecked exception Replace dummy handler with rethrow wrap the checked exception into an unchecked UnhandledException Throw UnhandledException
e class Unhandled EXception extends Runtime EXception public UnhandledException (Exception e, String msgt
class UnhandledException extends RuntimeException{ … public UnhandledException(Exception e, String msg){ … } }
e public void write File(String fileName, String data) Writer writer s null- may throw an IOException * writer= new Filewriter(fileName); may throw an IOException * writer.write(data) catch(IOException e)i throw new Unhandled Exception(e,"message"; finally ( code for cleanup */
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) { throw new UnhandledException(e,"message"); } finally {/* code for cleanup */} }
Furthor Refactoring
Furthor Refactoring