fixed uncought exception problem in neuralnets c++ examples

fixed the uncaught exception pointed out in the coverity scans: https://gist.github.com/khalednasr/521446d352f0bf33b283