use of com.ibm.jvm.dtfjview.commands.BaseJdmpviewCommand.ArtifactType in project openj9 by eclipse.
the class DTFJMethod method handleException.
/**
* Handle an exception thrown by the DTFJ API.
*
* @param cmd the command current executing the API. This is required to provide access to context information.
* @param cause exception to be handled
* @return textual data to be written out
*/
public static String handleException(BaseJdmpviewCommand cmd, Throwable cause) {
ctx = cmd.ctx;
StringBuffer sb = new StringBuffer();
// Try and determine the artifact type
StackTraceElement[] myStack = cause.getStackTrace();
ArtifactType artifactType = cmd.getArtifactType();
String artifactTypeName = null;
switch(artifactType) {
case core:
artifactTypeName = "core";
break;
case javacore:
artifactTypeName = "javacore";
break;
case phd:
artifactTypeName = "phd";
break;
default:
artifactTypeName = "Unknown artifact type";
break;
}
// Let's find out which DTFJ Class/Method was being used
DTFJMethod dMethod = getDTFJMethod(myStack, cmd);
if (cause instanceof DataUnavailable) {
if (dMethod == null) {
sb.append("Could not determine DTFJ class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == WORKS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" should have worked for a ");
sb.append(artifactTypeName);
sb.append(" but returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == CAN_FAIL) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" can fail for a ");
sb.append(artifactTypeName);
sb.append(" which is why it returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == FAILS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" is not supported for a ");
sb.append(artifactTypeName);
String s = cause.getLocalizedMessage();
if (s != null) {
sb.append(" causing: ");
sb.append(s);
}
}
} else if (cause instanceof CorruptDataException) {
CorruptData corruptData = ((CorruptDataException) cause).getCorruptData();
ImagePointer ip = corruptData.getAddress();
if (ip == null) {
sb.append("CorruptData found in dump at unknown address executing ");
if (dMethod == null) {
sb.append("an unknown class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
} else {
String addr = cmd.toHexStringAddr(ip.getAddress());
sb.append("CorruptData found in dump at address: ");
sb.append(addr);
sb.append(" causing: ");
sb.append(cause.getLocalizedMessage());
if (dMethod != null) {
sb.append(" executing ");
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
}
} else if (cause instanceof MemoryAccessException) {
sb.append(cause.getLocalizedMessage());
} else if (cause instanceof IllegalArgumentException) {
sb.append(cause.getLocalizedMessage());
} else {
// If we are here then something bad has really happened
// This is just debug code to help determine other problems this
// method has to deal with
sb.append("==========> Unexpected exception " + cause.getClass().getName() + " thrown: " + cause.getLocalizedMessage());
StringWriter st = new StringWriter();
cause.printStackTrace(new PrintWriter(st));
sb.append(st.toString());
}
return sb.toString();
}
Aggregations