Refactor exception handling in the OSPF protocol
- removed unnecessary throws of Exception from methods
- converted throws of generic Exception to specific OspfParseException
Change-Id: I9d07167d92f221a234e9eba4c6082deb165afc0b
diff --git a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/linksubtype/LocalInterfaceIpAddress.java b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/linksubtype/LocalInterfaceIpAddress.java
index 92c3183..0214ccc 100644
--- a/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/linksubtype/LocalInterfaceIpAddress.java
+++ b/protocols/ospf/protocol/src/main/java/org/onosproject/ospf/protocol/lsa/linksubtype/LocalInterfaceIpAddress.java
@@ -26,6 +26,7 @@
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
@@ -69,15 +70,15 @@
* Reads bytes from channel buffer.
*
* @param channelBuffer channel buffer instance
- * @throws Exception might throws exception while parsing buffer
+ * @throws OspfParseException might throws exception while parsing buffer
*/
- public void readFrom(ChannelBuffer channelBuffer) throws Exception {
+ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.addLocalInterfaceIPAddress(InetAddress.getByAddress(tempByteArray).getHostName());
- } catch (Exception e) {
+ } catch (UnknownHostException e) {
log.debug("Error::readFrom:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR,
OspfErrorType.BAD_MESSAGE);
@@ -89,9 +90,9 @@
* Gets local interface ip address as byte array.
*
* @return local interface ip address as byte array
- * @throws Exception might throws exception while parsing packet
+ * @throws OspfParseException might throws exception while parsing packet
*/
- public byte[] asBytes() throws Exception {
+ public byte[] asBytes() throws OspfParseException {
byte[] linkSubType = null;
byte[] linkSubTlvHeader = getTlvHeaderAsByteArray();
@@ -105,9 +106,9 @@
* Gets byte array of local interface ip address.
*
* @return byte array of local interface ip address
- * @throws Exception might throws exception while parsing packet
+ * @throws OspfParseException might throws exception while parsing packet
*/
- public byte[] getLinkSubTypeTlvBodyAsByteArray() throws Exception {
+ public byte[] getLinkSubTypeTlvBodyAsByteArray() throws OspfParseException {
List<Byte> linkSubTypeBody = new ArrayList<>();