2

For example if I was making an image API in Java would it be more beneficial to have multiple exception classes such as ImageSizeException, ImageFormatException or have a single exception class such as ImageException which has a string, enum ect for what kind of exception it is.

As a secondary question if you use multiple exception classes would it be more acceptable to group them in an exceptions package or with the classes that would throw them

2
  • This is very similar to stackoverflow.com/questions/20107848/…. Is there information there that helps you? Commented Dec 8, 2013 at 5:41
  • The one time I created many exception classes for a Java application, I put them in their own package. Commented Dec 8, 2013 at 6:39

2 Answers 2

0

You should certainly have a base exception, ImageException, which is the superclass of any others. Like Java has IOException.

Personally I would prefer one Exception with an Enum or int to subtype, but typical Java style is to have a lot of Exception subclasses. Your should probably follow convention.

Sign up to request clarification or add additional context in comments.

Comments

0

It's Better to have many exceptions.it will be easier debugging when your code is huge,and you could have ImageException as the superclassfor all these exceptions.

Comments