Java Positive flow and negative flow exception handling -
i writing java code fetch object information passing object id. case this: 1. not necessary object id's have information means returns null. 2. if id has information, return object. doing null check here.
if write else condition throws kalturaapiexception, throwing exception saying entryid not found , stopping execution there. problem should continue positive flow , should log ids no information. how handle scenario , how catch exception. please me resolving this. in advance.
try { entryinfo = getmedia(entry); if (entryinfo != null) { //here retrieving information object , setting 1 more object. } }catch(kalturaapiexception e){ e.getmessage(); }
inside getmedia method:
try { entryinfo = mediaservice.get(entryid); if (entryinfo != null) { return entryinfo; } } catch (kalturaapiexception e) { e.getmessage(); } return entryinfo;
if understand right, mediaservice.get throw kalturaapiexception. think don't need worry it. inside getmedia can
return mediaservice.get(entryid);
null object , null check in other method. exception catched in first method. (don't forget sign getmedia(long id) throw kalturaapiexception {...}
)
try { entryinfo = getmedia(entry); if (entryinfo != null) { // } }catch(kalturaapiexception e){ e.getmessage(); //log information, it's better use logger (log4j example) }
Comments
Post a Comment