本文整理汇总了Java中com.parse.ParseException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ParseException.getMessage方法的具体用法?Java ParseException.getMessage怎么用?Java ParseException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.parse.ParseException
的用法示例。
在下文中一共展示了ParseException.getMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getErrorMessage
import com.parse.ParseException; //导入方法依赖的package包/类
/**
* Tries to determine a friendly error message to display to the user, given a ParseException.
*
* @param e The exception.
*/
public static String getErrorMessage(ParseException e){
if(e != null){
switch(e.getCode()){
case CONNECTION_FAILED:
return "Connection failed";
case USERNAME_MISSING:
return "Username is missing";
case PASSWORD_MISSING:
return "Password is missing";
case EMAIL_MISSING:
return "Email is missing";
case USERNAME_TAKEN:
return "Username is taken";
case EMAIL_TAKEN:
return "Email is taken";
case TIMEOUT:
return "Request timed out";
default:
// If the default exception message isn't null, return it.
String exceptionMessage = e.getMessage();
if(exceptionMessage != null){
return exceptionMessage;
}
// Otherwise, check the cause's message
else{
Throwable cause;
String causeMessage;
cause = e.getCause();
// If the cause isn't null, get its message. Otherwise, set causeMessage to null
causeMessage = (cause == null) ? null : cause.getMessage();
// If the cause message isn't null, return it.
// Otherwise, just return the exception's error code.
if(causeMessage != null){
return String.format("%s (%d)", causeMessage, e.getCode());
} else{
return String.format("Error (%d)", e.getCode());
}
}
}
} else{
return "No error";
}
}