Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Exceptions be placed in a separate package?

I am taking on a project where all the Exceptions have been placed in a separate package com.myco.myproj.exceptions.

Is this good practice?

like image 346
TimP Avatar asked May 05 '09 15:05

TimP


People also ask

Which package is used for exception?

Uses of Exception in java. This exception is thrown by various methods in the java. awt. dnd package.

Should interface and implementation be in same package?

Placing both the interface and the implementation is common place, and doesn't seem to be a problem. Take for example the Java API -- most classes have both interfaces and their implementations included in the same package.

What is the package for exceptions in java?

Introduction. The java. lang. Exceptions provides for different exceptions thrown under java lang package.


2 Answers

I would expect the exceptions for a package to exist within that package. e.g.

com.oopsconsultancy.models.pricing 

would contain pricing models and related exceptions. Anything else seems a bit counter-intuitive.

like image 151
Brian Agnew Avatar answered Sep 19 '22 02:09

Brian Agnew


It is a bad practice.

It is a coincidental grouping. Packages should be coherent. Don't group exceptions, interfaces, enum, abstract classes, etc., into their own package. Group related concepts instead.

like image 28
Tom Hawtin - tackline Avatar answered Sep 20 '22 02:09

Tom Hawtin - tackline