davout
2007-05-07 14:06:36 UTC
I have a question about what the convention is for throwing exceptions on
validating data passed to business tier objects.
If I have a business tier service like where 'AccountManager', a business
tier that maintains accounts...
public class Account {
...
private String fTitle;
private String fAccountCode
....
}
public class AccountManager {
...
public void addAccount(Account aNewAccount);
...
}
... and any new account must have a non null title and a non-null account
code.
If the 'aNewAccount' parameter is passed with a null title field or a null
account code field what type of exception should I throw? Should the
business tier code be throwing an IllegalArgumentException? If so, how can
my GUI tier determine what field failed the validation test? Or should I use
a separate custom exceptions for each validation point? One custom exception
for title, another for alias etc.
validating data passed to business tier objects.
If I have a business tier service like where 'AccountManager', a business
tier that maintains accounts...
public class Account {
...
private String fTitle;
private String fAccountCode
....
}
public class AccountManager {
...
public void addAccount(Account aNewAccount);
...
}
... and any new account must have a non null title and a non-null account
code.
If the 'aNewAccount' parameter is passed with a null title field or a null
account code field what type of exception should I throw? Should the
business tier code be throwing an IllegalArgumentException? If so, how can
my GUI tier determine what field failed the validation test? Or should I use
a separate custom exceptions for each validation point? One custom exception
for title, another for alias etc.