In your program, you need to throw an exception and then output the error message in the user interface.
One scenario is to capture an exception when the final UI is displayed in the program, and then display the corresponding errormessage, and sometimes the program needs to customize the exception because it needs to throw an exception for business logic reasons.
How to centralize exception messages to correspond to the requirements of multiple languages, and these error messages need to be handled centrally.
Custom error messages.
Copy Code code as follows:
public class MyException extends Exception
{
Private static final long serialversionuid = 1L;
private type type;
Public myexception (Type type)
{
Super ();
This.type = type;
}
Public MyException (Throwable T, type type)
{
Super (T);
This.type = type;
}
Public String toString () {
return super.tostring () + "<" + Geterrortype (). GetErrorCode () + ">";
}
Public Type Geterrortype ()
{
return type;
}
public enum Type
{
System error
System_error ("99999"),
User authentication Error
User_auth ("03003");
Private String errorcode;
Type (String errorcode)
{
This.errorcode = ErrorCode;
}
Public String GetErrorCode ()
{
return this.errorcode;
}
}
}
Throw the error code here, and then you can get the error message for the resource file based on this error code.