java - How to handle nested exceptions without dropping any information? -
often have kind of pattern: (fictional example)
public void saveimage(image image) throws imageserviceexception { try { savetodatabase(image); //private method saving image's meta data (id, name, infos etc.) savetofile(image); //private method saving image's raw binary data } catch(sqlexception ex) { throw new imageserviceexception("could not save image database", ex); } catch(ioexception ex) { try { deletefromdatabase(image); } catch(sqlexception deletionex) //exception ignored !!! { throw new imageserviceexception("could not save image on disk , not delete image database", ex); } throw new imageserviceexception("could not save image on disk, database has been cleaned up", ex); } }
i'm trying save database infos image , save image on disk. if fails saved on disk, want rollback did in database. if fails, i'm not able log both errors. want able keep informations doing on in method. i've seen there's no aggregateexception
in java there's in c# wouldn't job since want throw checked exception.
how can handle such cases?
wiki
Comments
Post a Comment