Exceptions

Rule 3:Avoid unnecessary use of checked exceptions.

limited use of checked exception makes the code reliable but overuse makes it cumbersome and unreadble.
A method throwing checked excepton can not be used with java-8 stream,as it is not allowed.

Refrain from throwing the checked-exception, unless you are sure that the programmer of API can make better use of teh information of exception:
Example: no proper use –

} catch (TheCheckedException e) {
throw new AssertionError(); // Can’t happen!
}

Or this?
} catch (TheCheckedException e) {
e.printStackTrace(); // Oh well, we lose.
System.exit(1);
}

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment