internal static T MapException <T>(Exception x, bool remap, bool unused) where T : Exception { #if FIRST_PASS return(null); #else Exception org = x; bool nonJavaException = !(x is Throwable); if (nonJavaException && remap) { if (x is TypeInitializationException) { return((T)MapTypeInitializeException((TypeInitializationException)x, typeof(T))); } object obj = exceptions.get(x); Exception remapped = (Exception)obj; if (remapped == null) { remapped = Throwable.__mapImpl(x); if (remapped == x) { exceptions.put(x, NOT_REMAPPED); } else { exceptions.put(x, remapped); x = remapped; } } else if (remapped != NOT_REMAPPED) { x = remapped; } } if (IsInstanceOfType <T>(x, remap)) { Throwable t = x as Throwable; if (t != null) { if (!unused && t.tracePart1 == null && t.tracePart2 == null && t.stackTrace == Throwable.UNASSIGNED_STACK) { t.tracePart1 = new StackTrace(org, true); t.tracePart2 = new StackTrace(true); } if (t != org) { t.original = org; exceptions.remove(org); } } else { IDictionary data = x.Data; if (data != null && !data.IsReadOnly) { lock (data.SyncRoot) { if (!data.Contains(EXCEPTION_DATA_KEY)) { data.Add(EXCEPTION_DATA_KEY, new ExceptionInfoHelper(x, true)); } } } } if (nonJavaException && !remap) { exceptions.put(x, NOT_REMAPPED); } return((T)x); } return(null); #endif }
internal static T MapException <T>(Exception x, bool remap, bool unused) where T : Exception { #if FIRST_PASS return(null); #else Exception org = x; bool nonJavaException = !(x is Throwable); if (nonJavaException && remap) { if (x is TypeInitializationException) { return((T)MapTypeInitializeException((TypeInitializationException)x, typeof(T))); } object obj = exceptions.get(x); Exception remapped = (Exception)obj; if (remapped == null) { remapped = Throwable.__mapImpl(x); if (remapped == x) { exceptions.put(x, NOT_REMAPPED); } else { exceptions.put(x, remapped); x = remapped; } } else if (remapped != NOT_REMAPPED) { x = remapped; } } if (IsInstanceOfType <T>(x, remap)) { Throwable t = x as Throwable; if (t != null) { if (!unused && t.tracePart1 == null && t.tracePart2 == null && t.stackTrace == Throwable.UNASSIGNED_STACK) { #if !WINRT t.tracePart1 = new StackTrace(org, true); t.tracePart2 = new StackTrace(true); #else #endif } if (t != org) { t.original = org; exceptions.remove(org); } //[email protected]("About to try to replace stacktrace in remap"); if (t.stackTraceString == null && org.StackTrace != null) { //[email protected]("Replacing stack trace"); t.stackTraceString = org.StackTrace; } else if (t.stackTraceString != null) { //[email protected]("t stack trace is not null"); t.stackTraceString += "\nOriginating from:\nMessage=" + org.Message + "\n" + org.StackTrace; } } else { IDictionary data = x.Data; if (data != null && !data.IsReadOnly) { lock (data.SyncRoot) { if (!data.Contains(EXCEPTION_DATA_KEY)) { data.Add(EXCEPTION_DATA_KEY, new ExceptionInfoHelper(x, true)); } } } } if (nonJavaException && !remap) { exceptions.put(x, NOT_REMAPPED); } return((T)x); } return(null); #endif }