1 19 20 package jcifs.dcerpc; 21 22 import java.io.*; 23 24 import jcifs.util.Hexdump; 25 import jcifs.smb.WinError; 26 27 public class DcerpcException extends IOException implements DcerpcError, WinError { 28 29 static String getMessageByDcerpcError(int errcode) { 30 int min = 0; 31 int max = DCERPC_FAULT_CODES.length; 32 33 while (max >= min) { 34 int mid = (min + max) / 2; 35 36 if (errcode > DCERPC_FAULT_CODES[mid]) { 37 min = mid + 1; 38 } else if (errcode < DCERPC_FAULT_CODES[mid]) { 39 max = mid - 1; 40 } else { 41 return DCERPC_FAULT_MESSAGES[mid]; 42 } 43 } 44 45 return "0x" + Hexdump.toHexString(errcode, 8); 46 } 47 48 private int error; 49 private Throwable rootCause; 50 51 DcerpcException(String msg) { 52 super(msg); 53 } 54 DcerpcException(int error) { 55 super(getMessageByDcerpcError(error)); 56 this.error = error; 57 } 58 DcerpcException(String msg, Throwable rootCause) { 59 super(msg); 60 this.rootCause = rootCause; 61 } 62 public int getErrorCode() { 63 return error; 64 } 65 public Throwable getRootCause() { 66 return rootCause; 67 } 68 public String toString() { 69 if (rootCause != null) { 70 StringWriter sw = new StringWriter(); 71 PrintWriter pw = new PrintWriter(sw); 72 rootCause.printStackTrace(pw); 73 return super.toString() + "\n" + sw; 74 } 75 return super.toString(); 76 } 77 } 78 | Popular Tags |