1 package com4j; 2 3 12 public class ComException extends RuntimeException { 13 private final int hresult; 14 15 private final String fileName; 16 private final int line; 17 18 public ComException( String msg, int hresult, String fileName, int line ) { 19 super(Integer.toHexString(hresult)+' '+cutEOL(msg)); 20 this.hresult = hresult; 21 this.fileName = fileName; 22 this.line = line; 23 } 24 25 public ComException( String msg, String fileName, int line ) { 26 super(msg); 27 this.hresult = -1; 28 this.fileName = fileName; 29 this.line = line; 30 } 31 32 33 36 public int getHRESULT() { 37 return hresult; 38 } 39 40 private static String cutEOL( String s ) { 41 if(s==null) 42 return "(Unknown error)"; 43 if(s.endsWith("\r\n")) 44 return s.substring(0,s.length()-2); 45 else 46 return s; 47 } 48 49 public String toString() { 50 String s = super.toString(); 51 if(fileName!=null) { 52 s += ' '+fileName+':'+line; 53 } 54 return s; 55 } 56 } 57 | Popular Tags |