-2

I am trying to write code with exception handling but, I have one concern about which one is good to write in try catch block "Specific Exception" or "Generic Exception".

Performance wise which one is better.

Kindly help me with suggestions.

Thanks in advance.

Sushant
  • 30
  • 9
  • @raviraja I am not asking the difference between specific vs generic, I am asking about which one better with performance. – Sushant Dec 05 '18 at 07:03
  • did you read the accepted answer for that question? it clearly explains what is good and what is bad. – raviraja Dec 05 '18 at 07:04
  • @raviraja, I was not expecting this answer. I am expecting performance wise answer. – Sushant Dec 05 '18 at 07:10
  • @Sushant the performance of exceptions is terrible anyway. The difference in the performance - if any at all - is irrelevant. – Andy Turner Dec 05 '18 at 07:37

1 Answers1

0

I would suggest you to go for Specific exception handling. Coding in this direction makes sure developer knows possibly which exceptions can be thrown beforhand.

Another benefit is one can take action specific to a Exception type, rather than having a single catch block and handle Exception in generic way.

Dark Knight
  • 8,218
  • 4
  • 39
  • 58