1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
package com.robotraconteur;
/**
Helper class for working with RobotRaconteurException
*/
public class RobotRaconteurExceptionUtil
{
/**
Populates an entry with an exception
@param exception The exception to serialize
@param entry The entry to populate
*/
public static void exceptionToMessageEntry(Exception exception, MessageEntry entry)
{
String message=exception.getMessage();
if (message==null) message="";
MessageElementData param2 = null;
String errorsubname = null;
RobotRaconteurException rr_exp = null;
if (exception instanceof RobotRaconteurException)
{
rr_exp = (RobotRaconteurException)exception;
if (rr_exp.errorSubName != null)
{
errorsubname = rr_exp.errorSubName;
}
if (rr_exp.errorParam != null)
{
try
{
param2 = (MessageElementData)RobotRaconteurNode.s().packVarType(rr_exp.errorParam);
}
catch (Exception e)
{
//TODO: log error
}
}
}
try
{
@RR_ERRORS_CATCH@
if (rr_exp != null)
{
RobotRaconteurException r = rr_exp;
entry.setError(r.errorCode);
entry.addElement("errorname", r.error);
entry.addElement("errorstring", message);
if (r.errorSubName != null)
{
entry.addElement("errorsubname",r.errorSubName);
}
if (param2 != null)
{
entry.addElement("errorparam",param2);
}
}
else
{
entry.setError(MessageErrorType.MessageErrorType_RemoteError);
entry.addElement("errorname", exception.getClass().toString());
entry.addElement("errorstring", message);
}
}
finally
{
if (param2 != null)
{
param2.finalize();
}
}
}
private static RuntimeException errorInfoToException(long error_info_ptr)
{
return errorInfoToException(new HandlerErrorInfo(error_info_ptr,false));
}
public static RuntimeException errorInfoToException(HandlerErrorInfo error_info)
{
return errorCodeToException(MessageErrorType.swigToEnum((int)error_info.getError_code()), error_info.getErrorname(), error_info.getErrormessage(), error_info.getErrorsubname(), error_info.getParam_());
}
/**
Converts a MessageEntry containing an error to the correct exception
@param entry The entry containing an error
@return An populated exception
*/
public static RuntimeException errorCodeToException(MessageErrorType errorcode, String errorname, String errorstring, String errorsubname, MessageElement param_)
{
if (errorsubname == "")
{
errorsubname = null;
}
Object param2 = null;
if (param_ != null)
{
try
{
param2 = RobotRaconteurNode.s().unpackVarType(param_);
}
catch (Exception e)
{
//TODO: log error
}
finally
{
param_.finalize();
}
}
switch (errorcode)
{
case MessageErrorType_RemoteError:
RobotRaconteurException e1= new RobotRaconteurRemoteException(errorname, errorstring,errorsubname,param2);
RobotRaconteurException e2=RobotRaconteurNode.s().downCastException(e1);
return e2;
@RR_ERRORS_CASE@
default:
break;
}
return new RobotRaconteurException(errorcode, errorname, errorstring,errorsubname,param2);
}
}
|