0

Are there any 'best practices' or do's/dont's while throwing/handling exceptions in/from static methods ? Or Is there any difference in exception handling wrt static and non-static member functions ?

I could not find any such answer on the net. Thanks for help.

microMolvi
  • 616
  • 10
  • 29
JavaDeveloper
  • 4,772
  • 14
  • 66
  • 115

2 Answers2

1

There should't be any difference between an exception in a static method vs a non-static method.

Exceptions in static initializers are hard to handle, but that's because there's nowhere for you to put the try/catch block.

Community
  • 1
  • 1
DaoWen
  • 31,974
  • 6
  • 70
  • 100
1

IMHO, the answer is NO. But there are best practices for exception handling for sure.

You might like to consult Effective Java by Joshua Bloch - Second Edition - Chapter 9 (Exceptions).

Arnab Biswas
  • 4,176
  • 2
  • 37
  • 54