This, pretty basic, piece of code is quite common when handling encryption / decryption in Java.
final Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key, iv);
cipher.doFinal(*something*);
These three lines alone, potentially throw six exceptions and I'm not sure what's the cleanest (in terms of code readability) way to handle them.
A try with six catch clauses really looks like a smell to me.
Are there micropatterns or best practices, I am obviously missing, when working with such objects?
EDIT
Sorry, I think I didn't explain myself very well. My question is not really about avoiding a trycatch clause, but if there is a common way to handle similar situations.
The cryptographic exceptions are
NoSuchPaddingException, NoSuchAlgorithmException
InvalidAlgorithmParameterException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…