Fix possible crash without error being displayed, improve error handling in classloader path

Signed-off-by: Ross Allan <rallanpcl@gmail.com>