public static java.lang.Throwable TranslateException(java.lang.Throwable exc) { System.Exception newExc = null; if (exc is system.Exception) { return(exc); } var dlg = (ExceptionTranslator)exceptionMap.get( ((java.lang.Object)(object) exc).getClass()); if (dlg != null) { newExc = dlg(exc); } if (newExc == null) { if (exc is java.lang.NullPointerException) { newExc = new System.NullReferenceException(); } /*if (exc is java.lang.IllegalArgumentException) * newExc = new System.ArgumentException();*/ if (exc is java.lang.ArithmeticException && exc.getMessage() == "/ by zero") { newExc = new System.DivideByZeroException(); // "Attempted to divide by zero." } // also: IndexOutOfRangeException. define in Array? not necessarily. // fixme: move these to specialized exceptionMap ? if (newExc == null) { return(exc); } /*if (newExc == null) * { * // any throwable not deriving from system.Exception is assumed * // to be coming from the JVM or java code. If it was not mapped * // to some known .NET exception, wrap it in an ExternalException * // newExc = new Exception("Java exception: " + exc.GetType()); * // fixme System.Runtime.InteropServices.ExternalException ??? * Console.WriteLine("Created New Exception: "); * Console.WriteLine(newExc); * Console.WriteLine("Continuing..."); * }*/ } java.lang.Throwable newThrowable = (java.lang.Throwable)newExc; newThrowable.setStackTrace(exc.getStackTrace()); return(newThrowable); }
private static object ObjectModel(object ObjectModel) { if (!ClassLibraryStandard.HelperMethods.ObjectExists(ObjectModel)) { System.NullReferenceException ex = null; LogHelper.FatalNullReferenceException(ex); return(null); } return(ObjectModel); }
internal static bool RetryNullReferenceException(System.NullReferenceException ex, int iRetryAttempt) { if (iRetryAttempt == Constants.CONNECTION_RETRY_LIMIT) { FatalNullReferenceException(ex); } if (ex != null) { TraceRetryWriteLine(ex, iRetryAttempt, ex.HResult); ClassLibraryStandard.HelperMethods.ProcessSleep(2000); } return(true); }
public void Extensions_Safe_Catch5() { var ex0 = new Ex("ex"); var ex1 = new Ex1("ex"); var ex2 = new Ex2("ex"); var ex3 = new Ex3("ex"); var ex4 = new Ex4("ex"); var ex5 = new Ex5("ex"); var ex6 = new Ex6("ex"); var baseEx = new BaseEx("ex"); var subEx = new SubEx("ex"); var err1 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex1; }); var err2 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex2; }); var err3 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex3; }); var err4 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex4; }); var err5 = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => { throw ex5; }); Assert.IsFalse(err1.HasValue); Assert.IsFalse(err2.HasValue); Assert.IsFalse(err3.HasValue); Assert.IsFalse(err4.HasValue); Assert.IsFalse(err5.HasValue); Assert.IsInstanceOfType(err1.Match(x => null, ex => ex), typeof(Ex1)); Assert.IsInstanceOfType(err2.Match(x => null, ex => ex), typeof(Ex2)); Assert.IsInstanceOfType(err3.Match(x => null, ex => ex), typeof(Ex3)); Assert.IsInstanceOfType(err4.Match(x => null, ex => ex), typeof(Ex4)); Assert.IsInstanceOfType(err5.Match(x => null, ex => ex), typeof(Ex5)); Assert.AreEqual(err1.Match(x => null, ex => ex), ex1); Assert.AreEqual(err2.Match(x => null, ex => ex), ex2); Assert.AreEqual(err3.Match(x => null, ex => ex), ex3); Assert.AreEqual(err4.Match(x => null, ex => ex), ex4); Assert.AreEqual(err5.Match(x => null, ex => ex), ex5); CustomAssert.Throws <Ex>(() => Safe.Try <bool, Ex2, Ex3, Ex4, Ex5, Ex6>(() => { throw ex0; })); CustomAssert.Throws <Ex1>(() => Safe.Try <bool, Ex2, Ex3, Ex4, Ex5, Ex6>(() => { throw ex1; })); Safe.Try <bool, BaseEx, Ex2, Ex3, Ex4, Ex5>(() => { throw subEx; }); Safe.Try <bool, Ex, Ex2, Ex3, Ex4, Ex5>(() => { throw ex0; }); Safe.Try <bool, Ex, Ex2, Ex3, Ex4, Ex5>(() => { throw ex1; }); var success = Safe.Try <bool, Ex1, Ex2, Ex3, Ex4, Ex5>(() => true); Assert.IsTrue(success.ValueOr(false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void requireFileSystemWhenIdGeneratorFactoryNotProvided() internal virtual void RequireFileSystemWhenIdGeneratorFactoryNotProvided() { System.NullReferenceException exception = assertThrows(typeof(System.NullReferenceException), () => IdContextFactoryBuilder.Of(new CommunityIdTypeConfigurationProvider(), _jobScheduler).build()); assertThat(exception.Message, containsString("File system is required")); }