[core] Fix 500 handler

Make 500 handler more resilient by checking for exception type and value
before showing debugger. Also, if debugger cannot be shown, show real
500 error instead.