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
  • 636
  • 11
  • 30
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132

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
  • 32,589
  • 6
  • 74
  • 101
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,495
  • 3
  • 42
  • 60