I have a few custom exception classes that I created simply for the sake of having my own exception message:
public class DivideByZeroException extends Exception
{
@Override
public String toString()
{
return "ERROR: Expression cannot divide by 0";
}
}
I realize that this can be done by throwing an exception like:
throw new Exception("ERROR: Expression cannot divide by 0");
but this contains a prefix of java.lang.Exception:
in the string.
I think it's a bit ugly to remove the unwanted prefix from the string, but creating a class just for the exception message seems a bit excessive to me. Is there a different way to do this?