Separation of exception handling and logic

I thought that the previous code was not intuitive in returning -1, so I wrote the exception handling and logic separately.

Comment From: pivotal-cla

@devdynam0507 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@devdynam0507 Thank you for signing the Contributor License Agreement!