Almost all the exceptions I have ever written have been very lightweight, containing a String message and optionally a throwable. In some situations I have included some application specific enum or some other field.
public class MySpecialException()
{
private MyErrorCode errorCode;
public MySpecialException(String message, Throwable cause, MyErrorCode errorCode)
{
super(message, cause);
this.errorCode = errorCode;
}
....
}
Now I face a situation where I need to put in 5 or 6 fields in the exception because the error handler that catches them needs them to generate the output.
Would you consider that to be bad code? Can an exception be too big?
public class MySpecialException()
{
private String name;
private int age;
private int id;
private int height;
private String duck;
private String whatever;
....
}