1 4 package com.tc.util; 5 6 import com.tc.logging.TCLogger; 7 import java.lang.reflect.Array ; 8 9 12 public class Util { 13 private static final Error FATAL_ERROR = new Error ( 14 "Fatal error -- Please refer to console output and Terracotta log files for more information"); 15 16 22 public static String enumerateArray(Object array) { 23 StringBuffer buf = new StringBuffer (); 24 if (array != null) { 25 if (array.getClass().isArray()) { 26 for (int i = 0, n = Array.getLength(array); i < n; i++) { 27 if (i > 0) { 28 buf.append(", "); 29 } 30 buf.append("<<" + Array.get(array, i) + ">>"); 31 } 32 } else { 33 buf.append("<").append(array.getClass()).append(" is not an array>"); 34 } 35 } else { 36 buf.append("null"); 37 } 38 return buf.toString(); 39 } 40 41 public static void printLogAndRethrowError(Throwable t, TCLogger logger) { 42 printLogAndMaybeRethrowError(t, true, logger); 43 } 44 45 public static void printLogAndMaybeRethrowError(final Throwable t, final boolean rethrow, final TCLogger logger) { 46 50 try { 51 if (t != null) t.printStackTrace(); 52 logger.error(t); 53 } catch (Throwable err) { 54 try { 55 err.printStackTrace(); 56 } catch (Throwable err2) { 57 } 59 } finally { 60 if (rethrow) { 61 if (t instanceof RuntimeException ) { throw (RuntimeException ) t; } 63 if (t instanceof Error ) { throw (Error ) t; } 64 65 final RuntimeException re; 67 try { 68 re = new RuntimeException ("Unexpected Error " + t.getMessage(), t); 69 } catch (Throwable err3) { 70 try { 71 err3.printStackTrace(); 72 } catch (Throwable err4) { 73 } 75 throw FATAL_ERROR; 76 } 77 78 throw re; 79 } 80 } 81 } 82 83 public static void selfInterruptIfNeeded(boolean interruptFlag) { 84 if (interruptFlag) { 85 Thread.currentThread().interrupt(); 86 } 87 } 88 } | Popular Tags |