hi i belive that you need to write your own overriding Exception as to intcept the system exception that your code is throwing.
this is a example of one for email
hope it helps :)
---------------------------- emailclass --------------------------------
public class EmailAddress
{
private String domain = ""; // Domain component
private String emailAddress; // Full email address
private String server = ""; // Server component
private String user = ""; // User component
// Constructor default
public EmailAddress() throws EmailException
{
this("user@server.com");
}
// Constructor requires address
public EmailAddress(String address) throws EmailException
{
int pos1, pos2;
// Parse into components
pos1 = address.indexOf('@');
if (pos1 == -1)
{
throw new EmailException(address, "Email address requires an @");
}
this.user = address.substring(0, pos1); // Set the user
if (pos1 == 0)
{
throw new EmailException(address, "Email address requires a username");
}
pos2 = address.indexOf('.');
if (pos2 == -1 || (pos1+1) >= pos2)
{
throw new EmailException(address, "Email address requires a server name");
}
this.server = address.substring(pos1 + 1, pos2); // Set the server
this.domain = "com"; // Assumed for now
this.emailAddress = address; // Set full email address
}
// Return email address string
public String getAddress()
{
return this.emailAddress;
}
public String toString()
{
return this.getAddress() + "\n" + "user = " + this.user
+ "\nserver = " + this.server + "\ndomain = " + this.domain;
}
}
-------------------------- the custom exception ---------------------------------------------------------
public class EmailException extends Exception
{
private String invalidAddress;
public EmailException(String invalidAddress, String message) {
super(message);
this.invalidAddress = invalidAddress;
}
public String getInvalidAddress() {
return this.invalidAddress;
}
}
Edited by Vswe, 20 March 2010 - 02:04 AM.
Use Code tags(# button) when posting code