When is it good to put a method in a try/catch
block other than the ones which are critical?
For example if we have the Pattern.compile()
method and we know it can throw the exception IllegalArgumentException
and the PatternSyntaxException
. Should we put this method in a try/catch
block? I know that a try/catch
should be used when we know the method will fail. However, in this scenario a try/catch block
should be used, right? How do we decide whether to use a try/catch
or not because each method will throw an exception if it fails? At times the compiler will prompt us to use a try/catch
for certain methods but for certain ones we have to decide ourselves. What are the factors which help us decide this ?