private static bool TryGetJavaException(WebException e, out JavaException exception) { if (e.Response != null) { string[] types = e.Response.Headers.GetValues("X-OpenGamma-ExceptionType"); if (types != null) { if (types.Length > 1) { throw new ArgumentException("Too many exception types"); } string type = types[0]; string[] messages = e.Response.Headers.GetValues("X-OpenGamma-ExceptionMessage"); if (messages == null) { exception = new JavaException(type); return(true); } if (messages.Length > 1) { throw new ArgumentException("Too many exception messages"); } string message = messages[0]; exception = new JavaException(type, message); return(true); } } exception = null; return(false); }
/// <summary> /// Creates exception according to native code class and message. /// </summary> /// <param name="igniteInt">The ignite.</param> /// <param name="clsName">Exception class name.</param> /// <param name="msg">Exception message.</param> /// <param name="stackTrace">Native stack trace.</param> /// <param name="reader">Error data reader.</param> /// <param name="innerException">Inner exception.</param> /// <returns>Exception.</returns> public static Exception GetException(IIgniteInternal igniteInt, string clsName, string msg, string stackTrace, BinaryReader reader = null, Exception innerException = null) { // Set JavaException as immediate inner. var jex = new JavaException(clsName, msg, stackTrace, innerException); return(GetException(igniteInt, jex, reader)); }
JavaException ReadException() { references.Clear(); JavaException exception = new JavaException(ReadObject()); references.Clear(); return(exception); }
/// <summary> /// Creates exception according to native code class and message. /// </summary> /// <param name="igniteInt">The ignite.</param> /// <param name="innerException">Java exception.</param> /// <param name="reader">Error data reader.</param> /// <returns>Exception.</returns> public static Exception GetException(IIgniteInternal igniteInt, JavaException innerException, BinaryReader reader = null) { var ignite = igniteInt == null ? null : igniteInt.GetIgnite(); var msg = innerException.JavaMessage; var clsName = innerException.JavaClassName; ExceptionFactory ctor; if (Exs.TryGetValue(clsName, out ctor)) { var match = InnerClassRegex.Match(msg ?? string.Empty); ExceptionFactory innerCtor; if (match.Success && Exs.TryGetValue(match.Groups[1].Value, out innerCtor)) { return(ctor(clsName, msg, innerCtor(match.Groups[1].Value, match.Groups[2].Value, innerException, ignite), ignite)); } return(ctor(clsName, msg, innerException, ignite)); } if (ClsNoClsDefFoundErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(new IgniteException("Java class is not found (did you set IGNITE_HOME environment " + "variable?): " + msg, innerException)); } if (ClsNoSuchMthdErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(new IgniteException("Java class method is not found (did you set IGNITE_HOME environment " + "variable?): " + msg, innerException)); } if (ClsCachePartialUpdateErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(ProcessCachePartialUpdateException(igniteInt, msg, innerException.Message, reader)); } // Predefined mapping not found - check plugins. if (igniteInt != null && igniteInt.PluginProcessor != null) { ctor = igniteInt.PluginProcessor.GetExceptionMapping(clsName); if (ctor != null) { return(ctor(clsName, msg, innerException, ignite)); } } // Return default exception. return(new IgniteException(string.Format("Java exception occurred [class={0}, message={1}]", clsName, msg), innerException)); }
/// <summary> /// Creates exception according to native code class and message. /// </summary> /// <param name="ignite">The ignite.</param> /// <param name="clsName">Exception class name.</param> /// <param name="msg">Exception message.</param> /// <param name="stackTrace">Native stack trace.</param> /// <param name="reader">Error data reader.</param> /// <param name="innerException">Inner exception.</param> /// <returns>Exception.</returns> public static Exception GetException(Ignite ignite, string clsName, string msg, string stackTrace, BinaryReader reader = null, Exception innerException = null) { // Set JavaException as inner only if there is no InnerException. if (innerException == null) { innerException = new JavaException(clsName, msg, stackTrace); } ExceptionFactory ctor; if (Exs.TryGetValue(clsName, out ctor)) { var match = InnerClassRegex.Match(msg ?? string.Empty); ExceptionFactory innerCtor; if (match.Success && Exs.TryGetValue(match.Groups[1].Value, out innerCtor)) { return(ctor(clsName, msg, innerCtor(match.Groups[1].Value, match.Groups[2].Value, innerException, ignite), ignite)); } return(ctor(clsName, msg, innerException, ignite)); } if (ClsNoClsDefFoundErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(new IgniteException("Java class is not found (did you set IGNITE_HOME environment " + "variable?): " + msg, innerException)); } if (ClsNoSuchMthdErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(new IgniteException("Java class method is not found (did you set IGNITE_HOME environment " + "variable?): " + msg, innerException)); } if (ClsCachePartialUpdateErr.Equals(clsName, StringComparison.OrdinalIgnoreCase)) { return(ProcessCachePartialUpdateException(ignite, msg, stackTrace, reader)); } // Predefined mapping not found - check plugins. if (ignite != null) { ctor = ignite.PluginProcessor.GetExceptionMapping(clsName); if (ctor != null) { return(ctor(clsName, msg, innerException, ignite)); } } // Return default exception. return(new IgniteException(string.Format("Java exception occurred [class={0}, message={1}]", clsName, msg), innerException)); }
public void InnerException() { using (var t = new JniType("java/lang/Throwable")) { var outer = CreateThrowable(t, "Outer Exception"); SetThrowableCause(t, outer, "Inner Exception"); using (var e = new JavaException(ref outer, JniObjectReferenceOptions.CopyAndDispose)) { Assert.IsNotNull(e.InnerException); Assert.AreEqual("Inner Exception", e.InnerException.Message); Assert.AreEqual("Outer Exception", e.Message); } } }
static void MainDotNet2(List <JavaClass> classes, string outputPath) { #if !DEBUG string outputType = ""; try { #endif if (IsDirectoryPath(outputPath)) { #if !DEBUG outputType = "directory"; #endif WriteClassesToDir(classes, outputPath); } else if (outputPath.ToLower().EndsWith(".class")) { #if !DEBUG outputType = "file"; #endif if (classes.Count != 1) { Console.WriteLine("warning: input contains more than one class"); } using (var fileStream = new FileStream(outputPath, FileMode.Create)) { JavaWriter.WriteClass(classes[0], fileStream); } } else { #if !DEBUG outputType = "ZIP file"; #endif WriteClassesToZip(classes, outputPath); } #if !DEBUG } catch (Exception e) { if (!(e is JavaException)) { e = new JavaException(e.Message + " in writing output " + outputType, new JavaException.Where()); } throw e; } #endif }
public void InnerExceptionIsNotAProxy() { using (var t = new JniType("java/lang/Throwable")) { var outer = CreateThrowable(t, "Outer Exception"); var ex = new InvalidOperationException("Managed Exception!"); var exp = CreateJavaProxyThrowable(ex); SetThrowableCause(t, outer, exp.PeerReference); using (var e = new JavaException(ref outer, JniObjectReferenceOptions.CopyAndDispose)) { Assert.IsNotNull(e.InnerException); Assert.AreSame(ex, e.InnerException); } exp.Dispose(); } }
public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition) { var result = new JavaException(); reader.AddRef(result); string msg = null; JavaStackTrace[] traces = null; JavaException[] suppressedExceptions = null; JavaException innerException = null; foreach (var key in definition.Fields) { switch (key) { case "detailMessage": msg = reader.ReadString(); break; case "stackTrace": traces = reader.ReadObject <JavaStackTrace[]>(); break; case "suppressedExceptions": suppressedExceptions = reader.ReadObject <JavaException[]>(); break; case "cause": innerException = reader.ReadObject <JavaException>(); break; default: var info = reader.ReadObject(); if (info != result) { result.Data.Add(key, reader.ReadObject()); } break; } } result.ResumeException(definition.Type, msg, traces, suppressedExceptions, innerException == result ? null : innerException); return(result); }
public override object ReadMap(Hessian2Reader reader) { var result = new JavaException(); reader.AddRef(result); string msg = null; JavaStackTrace[] traces = null; JavaException[] suppressedExceptions = null; JavaException innerException = null; while (!reader.HasEnd()) { var key = reader.ReadString(); switch (key) { case "detailMessage": msg = reader.ReadString(); break; case "stackTrace": traces = reader.ReadObject <JavaStackTrace[]>(); break; case "suppressedExceptions": suppressedExceptions = reader.ReadObject <JavaException[]>(); break; case "cause": innerException = reader.ReadObject <JavaException>(); break; default: result.Data.Add(key, reader.ReadObject()); break; } } reader.ReadToEnd(); result.ResumeException(string.Empty, msg, traces, suppressedExceptions, innerException); return(result); }
public static void WithViewCycle(Action <ViewDefinitionCompiledArgs, IViewCycle, RemoteViewClient> action, string viewName = "Demo Equity Option Test View") { using (var executedMre = new ManualResetEventSlim(false)) using (var remoteViewClient = Context.ViewProcessor.CreateClient()) { ViewDefinitionCompiledArgs compiled = null; CycleCompletedArgs cycle = null; JavaException error = null; var listener = new EventViewResultListener(); listener.ProcessCompleted += delegate { executedMre.Set(); }; listener.CycleCompleted += delegate(object sender, CycleCompletedArgs e) { cycle = e; executedMre.Set(); }; listener.ViewDefinitionCompiled += delegate(object sender, ViewDefinitionCompiledArgs e) { compiled = e; }; listener.ViewDefinitionCompilationFailed += delegate(object sender, ViewDefinitionCompilationFailedArgs e) { error = e.Exception; executedMre.Set(); }; remoteViewClient.SetResultListener(listener); remoteViewClient.SetViewCycleAccessSupported(true); remoteViewClient.AttachToViewProcess(viewName, ExecutionOptions.SingleCycle); Assert.Null(remoteViewClient.CreateLatestCycleReference()); executedMre.Wait(TimeSpan.FromMinutes(1)); Assert.Null(error); Assert.NotNull(compiled); Assert.NotNull(cycle); using (var engineResourceReference = remoteViewClient.CreateLatestCycleReference()) { action(compiled, engineResourceReference.Value, remoteViewClient); } } }
/// <summary> /// Converts the exception. /// </summary> private Exception ConvertException(JavaException jex) { return(ExceptionUtils.GetException(_marsh.Ignite, jex)); }
private void SetError(JavaException javaException) { Exception buildException = javaException.BuildException(); SetError(buildException); }