Apply if/else style
Adds validation of port and catch for exception