0

I just want to know if it is possible to catch and handle signals from all thrown exceptions?

For example, a crash at runtime occurred and I want this signal handler to catch the exception for me to know the stacktrace of the crash. Yes, we know that we don't need this feature on development stage but if the user catches crashes on live app and declined to submit us the stacktrace and other info about the crash, how are we going to fix the crash and we will get many complains about these crashes.

Thanks!

dzep
  • 685
  • 1
  • 8
  • 20

1 Answers1

-1

Just implement try{}Throwable(Exception e){} block, which will handles both Exception as well as Errors.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
  • Thanks for the fast reply but this is not what I want. Let's say line 255 of class Example thrown an exception. Line 255 is not enclosed in a try-catch block, so what will happen is, the app will crash. So what I want to catch them all at runtime before crashing the app completely. :D – dzep Apr 21 '14 at 10:52
  • Then cover your piece of code in try-catch, which is doing some operation. – Pratik Dasa Apr 21 '14 at 10:55
  • Thank you but I can't do that. It is not a good coding practice. We should only do try-catch if the method throws exceptions. – dzep Apr 21 '14 at 11:06
  • First of all Try-Catch is better practise, you can catch the Exceptions, so I suggest you to use it whenever you need. – Pratik Dasa Apr 21 '14 at 11:09
  • Yup. What I meant on not a good coding practice is when we use try-catch in a block of code that we are expecting to crash (or may not). For example, we tried to call object.method() - not throwing exception (`void method` not `void method throws Exception`) - should we enclose it in a try-catch? What we should do is to make sure that the object instance is not null or garbage. Correct me if I'm wrong. This is how I understand your answer. I should enclosed all of my code in try-catch blocks. Am I correct? Thanks! – dzep Apr 21 '14 at 11:20