java - Handling API that throws two Exceptions with the same method, but without common interface -


i've been trying write logic regarding exception handling evernote java api. stumbled upon weird situation. there 2 exceptions - edamsystemexception , edamuserexception (documentation link)

both of exceptions have method edamerrorcode geterrorcode() lack common interface method.

i feels flaw in api design, since state of codes make sense edamsystemexception , others edamuserexceptions

since not state edamerrorcode bounds exception, , shielding myself situation of codes use in both of exception types wanted write try-catch block:

try {     clientfactory.createnotestoreclient(); } catch (edamsystemexception | edamuserexception ex) {     switch (ex.geterrorcode()) {         case invalid_auth:         case bad_data_format:             ..         case auth_expired:             ...         case rate_limit_reached:             ...         default:             ...     } } catch (texception ex) {    ... } 

but (obviously) cannot call ex.geterrorcode(). instance checking (instanceof + cast), seems not elegant.

i trying think generic solution problem, lack of common ancestor prevents me using bounded generic.

creating wrapper class 2 constructors , getmessage() method still forces me instance checking.

am missing or there no way around , have checking anyway?


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -