javacoding-stylemethod-names

Is there a particular naming convention for Java methods that throw exceptions?


I'm tempted to add a suffix like "Ex" to differentiate methods (with similar signatures) that throw Exceptions from those that don't.

Is there such a convention?


Solution

  • Yes, you name them the same as methods that don't.

    Isn't the exception specification enough?

    Edit: If you have similar methods that throw/not throw, I recommend the Parse/TryParse pattern (Parse being replaced by the operation). .NET Framework uses it frequently (Dictionary<T,K>.TryGetValue, Monitor.TryEnter, int.TryParse, etc. etc.).

    Edit: Coding Horror: TryParse and the Exception Tax