static unsafe MonoObject *CreateException(ExceptionType type, IntPtr arg0) { Exception rv = null; var str0 = Marshal.PtrToStringAuto(arg0); switch (type) { case ExceptionType.System_Exception: rv = new System.Exception(str0); break; case ExceptionType.System_InvalidCastException: rv = new System.InvalidCastException(str0); break; case ExceptionType.System_EntryPointNotFoundException: rv = new System.EntryPointNotFoundException(str0); break; case ExceptionType.System_OutOfMemoryException: rv = new System.OutOfMemoryException(); break; default: throw new ArgumentOutOfRangeException(nameof(type)); } return((MonoObject *)GetMonoObject(rv)); }
public void StripAggregateException() { _client.AddWrapperExceptions(typeof(AggregateException)); OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s"); AggregateException wrapper = new AggregateException(_exception, exception2); List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList(); Assert.AreEqual(2, exceptions.Count); Assert.Contains(_exception, exceptions); Assert.Contains(exception2, exceptions); }
public void ReflectionTypeLoadExceptionSupport() { FileNotFoundException ex1 = new FileNotFoundException(); OutOfMemoryException ex2 = new OutOfMemoryException(); ReflectionTypeLoadException wrapper = new ReflectionTypeLoadException(new Type[] { typeof(FakeRaygunClient), typeof(WrapperException) }, new Exception[] { ex1, ex2 }); RaygunErrorMessage message = RaygunErrorMessageBuilder.Build(wrapper); Assert.AreEqual(2, message.InnerErrors.Count()); Assert.AreEqual("System.IO.FileNotFoundException", message.InnerErrors[0].ClassName); Assert.AreEqual("System.OutOfMemoryException", message.InnerErrors[1].ClassName); Assert.IsTrue(message.InnerErrors[0].Data["Type"].ToString().Contains("FakeRaygunClient")); Assert.IsTrue(message.InnerErrors[1].Data["Type"].ToString().Contains("WrapperException")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldCopeWithHardExceptionsLikeOutOfMemory() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCopeWithHardExceptionsLikeOutOfMemory() { // GIVEN System.OutOfMemoryException oom = new System.OutOfMemoryException(); when(_master.pullUpdates(any(typeof(RequestContext)))).thenThrow(oom).thenReturn(Response.empty()); // WHEN making the first pull _updatePuller.pullUpdates(); // THEN the OOM should be caught and logged _logProvider.assertAtLeastOnce(inLog(typeof(SlaveUpdatePuller)).error(org.hamcrest.Matchers.any(typeof(string)), sameInstance(oom))); // WHEN that has passed THEN we should still be making pull attempts. _updatePuller.pullUpdates(); }
/// <summary>IndexInput methods </summary> public override void ReadInternal(byte[] b, int offset, int len) { lock (file) { long position = FilePointer; if (position != file.position) { file.BaseStream.Seek(position, System.IO.SeekOrigin.Begin); file.position = position; } int total = 0; try { do { int readLength; if (total + chunkSize > len) { readLength = len - total; } else { // LUCENE-1566 - work around JVM Bug by breaking very large reads into chunks readLength = chunkSize; } int i = file.Read(b, offset + total, readLength); if (i == -1) { throw new System.IO.IOException("read past EOF"); } file.position += i; total += i; }while (total < len); } catch (System.OutOfMemoryException e) { // propagate OOM up and add a hint for 32bit VM Users hitting the bug // with a large chunk size in the fast path. System.OutOfMemoryException outOfMemoryError = new System.OutOfMemoryException("OutOfMemoryError likely caused by the Sun VM Bug described in " + "https://issues.apache.org/jira/browse/LUCENE-1566; try calling FSDirectory.setReadChunkSize " + "with a a value smaller than the current chunks size (" + chunkSize + ")", e); throw outOfMemoryError; } } }
public static Exception?GetRuntimeException(ExceptionIDs id) { if (!SafeToPerformRichExceptionSupport) { return(null); } // This method is called by the runtime's EH dispatch code and is not allowed to leak exceptions // back into the dispatcher. try { // @TODO: this function should return pre-allocated exception objects, either frozen in the image // or preallocated during DllMain(). In particular, this function will be called when out of memory, // and failure to create an exception will result in infinite recursion and therefore a stack overflow. switch (id) { case ExceptionIDs.OutOfMemory: Exception outOfMemoryException = PreallocatedOutOfMemoryException.Instance; // If possible, try to allocate proper out-of-memory exception with error message and stack trace if (!t_allocatingOutOfMemoryException) { t_allocatingOutOfMemoryException = true; try { outOfMemoryException = new OutOfMemoryException(); } catch { } t_allocatingOutOfMemoryException = false; } return(outOfMemoryException); case ExceptionIDs.Arithmetic: return(new ArithmeticException()); case ExceptionIDs.ArrayTypeMismatch: return(new ArrayTypeMismatchException()); case ExceptionIDs.DivideByZero: return(new DivideByZeroException()); case ExceptionIDs.IndexOutOfRange: return(new IndexOutOfRangeException()); case ExceptionIDs.InvalidCast: return(new InvalidCastException()); case ExceptionIDs.Overflow: return(new OverflowException()); case ExceptionIDs.NullReference: return(new NullReferenceException()); case ExceptionIDs.AccessViolation: FailFast("Access Violation: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The application will be terminated since this platform does not support throwing an AccessViolationException."); return(null); case ExceptionIDs.DataMisaligned: return(new DataMisalignedException()); case ExceptionIDs.EntrypointNotFound: return(new EntryPointNotFoundException()); case ExceptionIDs.AmbiguousImplementation: return(new AmbiguousImplementationException()); default: FailFast("The runtime requires an exception for a case that this class library does not understand."); return(null); } } catch { return(null); // returning null will cause the runtime to FailFast via the class library. } }
/// <summary> /// This does a mapping from hr to the exception and also takes care of making default exception in case of classic COM as COMException. /// and in winrt and marshal APIs as Exception. /// </summary> /// <param name="errorCode"></param> /// <param name="message"></param> /// <param name="createCOMException"></param> /// <returns></returns> internal static Exception GetMappingExceptionForHR(int errorCode, string message, bool createCOMException, bool hasErrorInfo) { if (errorCode >= 0) { return null; } Exception exception = null; bool shouldDisplayHR = false; switch (errorCode) { case __HResults.COR_E_NOTFINITENUMBER: // NotFiniteNumberException case __HResults.COR_E_ARITHMETIC: exception = new ArithmeticException(); break; case __HResults.COR_E_ARGUMENT: case unchecked((int)0x800A01C1): case unchecked((int)0x800A01C2): case __HResults.CLR_E_BIND_UNRECOGNIZED_IDENTITY_FORMAT: exception = new ArgumentException(); if (errorCode != __HResults.COR_E_ARGUMENT) shouldDisplayHR = true; break; case __HResults.E_BOUNDS: case __HResults.COR_E_ARGUMENTOUTOFRANGE: case __HResults.ERROR_NO_UNICODE_TRANSLATION: exception = new ArgumentOutOfRangeException(); if (errorCode != __HResults.COR_E_ARGUMENTOUTOFRANGE) shouldDisplayHR = true; break; case __HResults.COR_E_ARRAYTYPEMISMATCH: exception = new ArrayTypeMismatchException(); break; case __HResults.COR_E_BADIMAGEFORMAT: case __HResults.CLDB_E_FILE_OLDVER: case __HResults.CLDB_E_INDEX_NOTFOUND: case __HResults.CLDB_E_FILE_CORRUPT: case __HResults.COR_E_NEWER_RUNTIME: case __HResults.COR_E_ASSEMBLYEXPECTED: case __HResults.ERROR_BAD_EXE_FORMAT: case __HResults.ERROR_EXE_MARKED_INVALID: case __HResults.CORSEC_E_INVALID_IMAGE_FORMAT: case __HResults.ERROR_NOACCESS: case __HResults.ERROR_INVALID_ORDINAL: case __HResults.ERROR_INVALID_DLL: case __HResults.ERROR_FILE_CORRUPT: case __HResults.COR_E_LOADING_REFERENCE_ASSEMBLY: case __HResults.META_E_BAD_SIGNATURE: exception = new BadImageFormatException(); // Always show HR for BadImageFormatException shouldDisplayHR = true; break; case __HResults.COR_E_CUSTOMATTRIBUTEFORMAT: exception = new FormatException(); break; // CustomAttributeFormatException case __HResults.COR_E_DATAMISALIGNED: exception = InteropExtensions.CreateDataMisalignedException(message); // TODO: Do we need to add msg here? break; case __HResults.COR_E_DIVIDEBYZERO: case __HResults.CTL_E_DIVISIONBYZERO: exception = new DivideByZeroException(); if (errorCode != __HResults.COR_E_DIVIDEBYZERO) shouldDisplayHR = true; break; case __HResults.COR_E_DLLNOTFOUND: #if ENABLE_WINRT exception = new DllNotFoundException(); #endif break; case __HResults.COR_E_DUPLICATEWAITOBJECT: exception = new ArgumentException(); break; // DuplicateWaitObjectException case __HResults.COR_E_ENDOFSTREAM: case unchecked((int)0x800A003E): exception = new System.IO.EndOfStreamException(); if (errorCode != __HResults.COR_E_ENDOFSTREAM) shouldDisplayHR = true; break; case __HResults.COR_E_TYPEACCESS: // TypeAccessException case __HResults.COR_E_ENTRYPOINTNOTFOUND: exception = new TypeLoadException(); break; // EntryPointNotFoundException case __HResults.COR_E_EXCEPTION: exception = new Exception(); break; case __HResults.COR_E_DIRECTORYNOTFOUND: case __HResults.STG_E_PATHNOTFOUND: case __HResults.CTL_E_PATHNOTFOUND: exception = new System.IO.DirectoryNotFoundException(); if (errorCode != __HResults.COR_E_DIRECTORYNOTFOUND) shouldDisplayHR = true; break; case __HResults.COR_E_FILELOAD: case __HResults.FUSION_E_INVALID_PRIVATE_ASM_LOCATION: case __HResults.FUSION_E_SIGNATURE_CHECK_FAILED: case __HResults.FUSION_E_LOADFROM_BLOCKED: case __HResults.FUSION_E_CACHEFILE_FAILED: case __HResults.FUSION_E_ASM_MODULE_MISSING: case __HResults.FUSION_E_INVALID_NAME: case __HResults.FUSION_E_PRIVATE_ASM_DISALLOWED: case __HResults.FUSION_E_HOST_GAC_ASM_MISMATCH: case __HResults.COR_E_MODULE_HASH_CHECK_FAILED: case __HResults.FUSION_E_REF_DEF_MISMATCH: case __HResults.SECURITY_E_INCOMPATIBLE_SHARE: case __HResults.SECURITY_E_INCOMPATIBLE_EVIDENCE: case __HResults.SECURITY_E_UNVERIFIABLE: case __HResults.COR_E_FIXUPSINEXE: case __HResults.ERROR_TOO_MANY_OPEN_FILES: case __HResults.ERROR_SHARING_VIOLATION: case __HResults.ERROR_LOCK_VIOLATION: case __HResults.ERROR_OPEN_FAILED: case __HResults.ERROR_DISK_CORRUPT: case __HResults.ERROR_UNRECOGNIZED_VOLUME: case __HResults.ERROR_DLL_INIT_FAILED: case __HResults.FUSION_E_CODE_DOWNLOAD_DISABLED: case __HResults.CORSEC_E_MISSING_STRONGNAME: case __HResults.MSEE_E_ASSEMBLYLOADINPROGRESS: case __HResults.ERROR_FILE_INVALID: exception = new System.IO.FileLoadException(); shouldDisplayHR = true; break; case __HResults.COR_E_PATHTOOLONG: exception = new System.IO.PathTooLongException(); break; case __HResults.COR_E_IO: case __HResults.CTL_E_DEVICEIOERROR: case unchecked((int)0x800A793C): case unchecked((int)0x800A793D): exception = new System.IO.IOException(); if (errorCode != __HResults.COR_E_IO) shouldDisplayHR = true; break; case __HResults.ERROR_FILE_NOT_FOUND: case __HResults.ERROR_MOD_NOT_FOUND: case __HResults.ERROR_INVALID_NAME: case __HResults.CTL_E_FILENOTFOUND: case __HResults.ERROR_BAD_NET_NAME: case __HResults.ERROR_BAD_NETPATH: case __HResults.ERROR_NOT_READY: case __HResults.ERROR_WRONG_TARGET_NAME: case __HResults.INET_E_UNKNOWN_PROTOCOL: case __HResults.INET_E_CONNECTION_TIMEOUT: case __HResults.INET_E_CANNOT_CONNECT: case __HResults.INET_E_RESOURCE_NOT_FOUND: case __HResults.INET_E_OBJECT_NOT_FOUND: case __HResults.INET_E_DOWNLOAD_FAILURE: case __HResults.INET_E_DATA_NOT_AVAILABLE: case __HResults.ERROR_DLL_NOT_FOUND: case __HResults.CLR_E_BIND_ASSEMBLY_VERSION_TOO_LOW: case __HResults.CLR_E_BIND_ASSEMBLY_PUBLIC_KEY_MISMATCH: case __HResults.CLR_E_BIND_ASSEMBLY_NOT_FOUND: exception = new System.IO.FileNotFoundException(); shouldDisplayHR = true; break; case __HResults.COR_E_FORMAT: exception = new FormatException(); break; case __HResults.COR_E_INDEXOUTOFRANGE: case unchecked((int)0x800a0009): exception = new IndexOutOfRangeException(); if (errorCode != __HResults.COR_E_INDEXOUTOFRANGE) shouldDisplayHR = true; break; case __HResults.COR_E_INVALIDCAST: exception = new InvalidCastException(); break; case __HResults.COR_E_INVALIDCOMOBJECT: exception = new InvalidComObjectException(); break; case __HResults.COR_E_INVALIDOLEVARIANTTYPE: exception = new InvalidOleVariantTypeException(); break; case __HResults.COR_E_INVALIDOPERATION: case __HResults.E_ILLEGAL_STATE_CHANGE: case __HResults.E_ILLEGAL_METHOD_CALL: case __HResults.E_ILLEGAL_DELEGATE_ASSIGNMENT: case __HResults.APPMODEL_ERROR_NO_PACKAGE: exception = new InvalidOperationException(); if (errorCode != __HResults.COR_E_INVALIDOPERATION) shouldDisplayHR = true; break; case __HResults.COR_E_MARSHALDIRECTIVE: exception = new MarshalDirectiveException(); break; case __HResults.COR_E_METHODACCESS: // MethodAccessException case __HResults.META_E_CA_FRIENDS_SN_REQUIRED: // MethodAccessException case __HResults.COR_E_FIELDACCESS: case __HResults.COR_E_MEMBERACCESS: exception = new MemberAccessException(); if (errorCode != __HResults.COR_E_METHODACCESS) shouldDisplayHR = true; break; case __HResults.COR_E_MISSINGFIELD: // MissingFieldException case __HResults.COR_E_MISSINGMETHOD: // MissingMethodException case __HResults.COR_E_MISSINGMEMBER: case unchecked((int)0x800A01CD): exception = new MissingMemberException(); break; case __HResults.COR_E_MISSINGMANIFESTRESOURCE: exception = new System.Resources.MissingManifestResourceException(); break; case __HResults.COR_E_NOTSUPPORTED: case unchecked((int)0x800A01B6): case unchecked((int)0x800A01BD): case unchecked((int)0x800A01CA): case unchecked((int)0x800A01CB): exception = new NotSupportedException(); if (errorCode != __HResults.COR_E_NOTSUPPORTED) shouldDisplayHR = true; break; case __HResults.COR_E_NULLREFERENCE: exception = new NullReferenceException(); break; case __HResults.COR_E_OBJECTDISPOSED: case __HResults.RO_E_CLOSED: // No default constructor exception = new ObjectDisposedException(String.Empty); break; case __HResults.COR_E_OPERATIONCANCELED: #if ENABLE_WINRT exception = new OperationCanceledException(); #endif break; case __HResults.COR_E_OVERFLOW: case __HResults.CTL_E_OVERFLOW: exception = new OverflowException(); break; case __HResults.COR_E_PLATFORMNOTSUPPORTED: exception = new PlatformNotSupportedException(message); break; case __HResults.COR_E_RANK: exception = new RankException(); break; case __HResults.COR_E_REFLECTIONTYPELOAD: #if ENABLE_WINRT exception = new System.Reflection.ReflectionTypeLoadException(null, null); #endif break; case __HResults.COR_E_SECURITY: case __HResults.CORSEC_E_INVALID_STRONGNAME: case __HResults.CTL_E_PERMISSIONDENIED: case unchecked((int)0x800A01A3): case __HResults.CORSEC_E_INVALID_PUBLICKEY: case __HResults.CORSEC_E_SIGNATURE_MISMATCH: exception = new System.Security.SecurityException(); break; case __HResults.COR_E_SAFEARRAYRANKMISMATCH: exception = new SafeArrayRankMismatchException(); break; case __HResults.COR_E_SAFEARRAYTYPEMISMATCH: exception = new SafeArrayTypeMismatchException(); break; case __HResults.COR_E_SERIALIZATION: exception = new System.Runtime.Serialization.SerializationException(message); break; case __HResults.COR_E_SYNCHRONIZATIONLOCK: exception = new System.Threading.SynchronizationLockException(); break; case __HResults.COR_E_TARGETINVOCATION: exception = new System.Reflection.TargetInvocationException(null); break; case __HResults.COR_E_TARGETPARAMCOUNT: exception = new System.Reflection.TargetParameterCountException(); break; case __HResults.COR_E_TYPEINITIALIZATION: exception = InteropExtensions.CreateTypeInitializationException(message); break; case __HResults.COR_E_TYPELOAD: case __HResults.RO_E_METADATA_NAME_NOT_FOUND: case __HResults.CLR_E_BIND_TYPE_NOT_FOUND: exception = new TypeLoadException(); if (errorCode != __HResults.COR_E_TYPELOAD) shouldDisplayHR = true; break; case __HResults.COR_E_UNAUTHORIZEDACCESS: case __HResults.CTL_E_PATHFILEACCESSERROR: case unchecked((int)0x800A014F): exception = new UnauthorizedAccessException(); shouldDisplayHR = true; break; case __HResults.COR_E_VERIFICATION: exception = new System.Security.VerificationException(); break; case __HResults.E_NOTIMPL: exception = new NotImplementedException(); break; case __HResults.E_OUTOFMEMORY: case __HResults.CTL_E_OUTOFMEMORY: case unchecked((int)0x800A7919): exception = new OutOfMemoryException(); if (errorCode != __HResults.E_OUTOFMEMORY) shouldDisplayHR = true; break; #if ENABLE_WINRT case __HResults.E_XAMLPARSEFAILED: exception = ConstructExceptionUsingReflection( "Windows.UI.Xaml.Markup.XamlParseException, System.Runtime.WindowsRuntime.UI.Xaml, Version=4.0.0.0", message); break; case __HResults.E_ELEMENTNOTAVAILABLE: exception = ConstructExceptionUsingReflection( "Windows.UI.Xaml.Automation.ElementNotAvailableException, System.Runtime.WindowsRuntime.UI.Xaml, Version=4.0.0.0", message); break; case __HResults.E_ELEMENTNOTENABLED: exception = ConstructExceptionUsingReflection( "Windows.UI.Xaml.Automation.ElementNotEnabledException, System.Runtime.WindowsRuntime.UI.Xaml, Version=4.0.0.0", message); break; case __HResults.E_LAYOUTCYCLE: exception = ConstructExceptionUsingReflection( "Windows.UI.Xaml.LayoutCycleException, System.Runtime.WindowsRuntime.UI.Xaml, Version=4.0.0.0", message); break; #endif // ENABLE_WINRT case __HResults.COR_E_AMBIGUOUSMATCH: // AmbiguousMatchException case __HResults.COR_E_APPLICATION: // ApplicationException case __HResults.COR_E_APPDOMAINUNLOADED: // AppDomainUnloadedException case __HResults.COR_E_CANNOTUNLOADAPPDOMAIN: // CannotUnloadAppDomainException case __HResults.COR_E_CODECONTRACTFAILED: // ContractException case __HResults.COR_E_CONTEXTMARSHAL: // ContextMarshalException case __HResults.CORSEC_E_CRYPTO: // CryptographicException case __HResults.CORSEC_E_CRYPTO_UNEX_OPER: // CryptographicUnexpectedOperationException case __HResults.COR_E_EXECUTIONENGINE: // ExecutionEngineException case __HResults.COR_E_INSUFFICIENTEXECUTIONSTACK: // InsufficientExecutionStackException case __HResults.COR_E_INVALIDFILTERCRITERIA: // InvalidFilterCriteriaException case __HResults.COR_E_INVALIDPROGRAM: // InvalidProgramException case __HResults.COR_E_MULTICASTNOTSUPPORTED: // MulticastNotSupportedException case __HResults.COR_E_REMOTING: // RemotingException case __HResults.COR_E_RUNTIMEWRAPPED: // RuntimeWrappedException case __HResults.COR_E_SERVER: // ServerException case __HResults.COR_E_STACKOVERFLOW: // StackOverflowException case __HResults.CTL_E_OUTOFSTACKSPACE: // StackOverflowException case __HResults.COR_E_SYSTEM: // SystemException case __HResults.COR_E_TARGET: // TargetException case __HResults.COR_E_THREADABORTED: // TargetException case __HResults.COR_E_THREADINTERRUPTED: // ThreadInterruptedException case __HResults.COR_E_THREADSTATE: // ThreadStateException case __HResults.COR_E_THREADSTART: // ThreadStartException case __HResults.COR_E_TYPEUNLOADED: // TypeUnloadedException case __HResults.CORSEC_E_POLICY_EXCEPTION: // PolicyException case __HResults.CORSEC_E_NO_EXEC_PERM: // PolicyException case __HResults.CORSEC_E_MIN_GRANT_FAIL: // PolicyException case __HResults.CORSEC_E_XMLSYNTAX: // XmlSyntaxException case __HResults.ISS_E_ALLOC_TOO_LARGE: // IsolatedStorageException case __HResults.ISS_E_BLOCK_SIZE_TOO_SMALL: // IsolatedStorageException case __HResults.ISS_E_CALLER: // IsolatedStorageException case __HResults.ISS_E_CORRUPTED_STORE_FILE: // IsolatedStorageException case __HResults.ISS_E_CREATE_DIR: // IsolatedStorageException case __HResults.ISS_E_CREATE_MUTEX: // IsolatedStorageException case __HResults.ISS_E_DEPRECATE: // IsolatedStorageException case __HResults.ISS_E_FILE_NOT_MAPPED: // IsolatedStorageException case __HResults.ISS_E_FILE_WRITE: // IsolatedStorageException case __HResults.ISS_E_GET_FILE_SIZE: // IsolatedStorageException case __HResults.ISS_E_ISOSTORE: // IsolatedStorageException case __HResults.ISS_E_LOCK_FAILED: // IsolatedStorageException case __HResults.ISS_E_MACHINE: // IsolatedStorageException case __HResults.ISS_E_MACHINE_DACL: // IsolatedStorageException case __HResults.ISS_E_MAP_VIEW_OF_FILE: // IsolatedStorageException case __HResults.ISS_E_OPEN_FILE_MAPPING: // IsolatedStorageException case __HResults.ISS_E_OPEN_STORE_FILE: // IsolatedStorageException case __HResults.ISS_E_PATH_LENGTH: // IsolatedStorageException case __HResults.ISS_E_SET_FILE_POINTER: // IsolatedStorageException case __HResults.ISS_E_STORE_NOT_OPEN: // IsolatedStorageException case __HResults.ISS_E_STORE_VERSION: // IsolatedStorageException case __HResults.ISS_E_TABLE_ROW_NOT_FOUND: // IsolatedStorageException case __HResults.ISS_E_USAGE_WILL_EXCEED_QUOTA: // IsolatedStorageException case __HResults.E_FAIL: default: break; } if (exception == null) { if (createCOMException) { exception = new COMException(); if (errorCode != __HResults.E_FAIL) shouldDisplayHR = true; } else { exception = new Exception(); if (errorCode != __HResults.COR_E_EXCEPTION) shouldDisplayHR = true; } } bool shouldConstructMessage = false; if (hasErrorInfo) { // If there is a IErrorInfo/IRestrictedErrorInfo, only construct a new error message if // the message is not available and do not use the shouldDisplayHR setting if (message == null) shouldConstructMessage = true; } else { // If there is no IErrorInfo, use the shouldDisplayHR setting from the big switch/case above shouldConstructMessage = shouldDisplayHR; } if (shouldConstructMessage) { // // Append the HR into error message, just in case the app wants to look at the HR in // message to determine behavior. We didn't expose HResult property until v4.5 and // GetHRFromException has side effects so probably Message was their only choice. // This behavior is probably not exactly the same as in desktop but it is fine to append // more message at the end. In any case, having the HR in the error message are helpful // to developers. // This makes sure: // 1. We always have a HR 0xNNNNNNNN in the message // 2. Put in a nice "Exception thrown from HRESULT" message if we can // 3. Wrap it in () if there is an existing message // // TODO: Add Symbolic Name into Messaage, convert 0x80020006 to DISP_E_UNKNOWNNAME string hrMessage = String.Format("{0} 0x{1}", SR.Excep_FromHResult, errorCode.LowLevelToString()); message = ExternalInterop.GetMessage(errorCode); // Always make sure we have at least the HRESULT part in retail build or when the message // is empty. if (message == null) message = hrMessage; else message = message + " (" + hrMessage + ")"; } if (message != null) { // Set message explicitly rather than calling constructor because certain ctors would append a // prefix to the message and that is not what we want InteropExtensions.SetExceptionMessage(exception, message); } InteropExtensions.SetExceptionErrorCode(exception, errorCode); return exception; }
internal static Exception GetExceptionFromCOMException(COMException e) { Exception passwordException; int errorCode = e.ErrorCode; string message = e.Message; if (errorCode != -2147024891) { if (errorCode == -2147022651 || errorCode == -2147024810 || errorCode == 0x8007052) { passwordException = new PasswordException(message, e); } else { if (errorCode == -2147022672 || errorCode == -2147019886) { passwordException = new PrincipalExistsException(message, e); } else { if (errorCode != -2147023570) { if (errorCode != -2147016657) { if (errorCode != -2147016651) { if (errorCode != -2147024888) { if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689) { passwordException = new PrincipalServerDownException(message, e, errorCode, null); } else { passwordException = new PrincipalOperationException(message, e, errorCode); } } else { passwordException = new OutOfMemoryException(); } } else { passwordException = new InvalidOperationException(message, e); } } else { passwordException = new InvalidOperationException(message, e); } } else { passwordException = new AuthenticationException(message, e); } } } } else { passwordException = new UnauthorizedAccessException(message, e); } return passwordException; }
// Eagerly preallocate instance of out of memory exception to avoid infinite recursion once we run out of memory internal static void Initialize() { Instance = new OutOfMemoryException(message: null); // Cannot call the nullary constructor as that triggers non-trivial resource manager logic. }
public void FormatException_Test() { ScriptEngine engine = _runtime.GetEngine("py"); ExceptionOperations es = engine.GetService<ExceptionOperations>(); OutOfMemoryException e = new OutOfMemoryException(); string result = es.FormatException(e); Assert.AreNotEqual(e.Message, result); }
private Exception HandleMemoryException(OutOfMemoryException e) { throw treeStore.SetErrorState(e); }
/// <summary>IndexInput methods </summary> public override void ReadInternal(byte[] b, int offset, int len) { lock (file) { long position = GetFilePointer(); if (position != file.position) { file.BaseStream.Seek(position, System.IO.SeekOrigin.Begin); file.position = position; } int total = 0; try { do { int readLength; if (total + chunkSize > len) { readLength = len - total; } else { // LUCENE-1566 - work around JVM Bug by breaking very large reads into chunks readLength = chunkSize; } int i = file.Read(b, offset + total, readLength); if (i == - 1) { throw new System.IO.IOException("read past EOF"); } file.position += i; total += i; } while (total < len); } catch (System.OutOfMemoryException e) { // propagate OOM up and add a hint for 32bit VM Users hitting the bug // with a large chunk size in the fast path. System.OutOfMemoryException outOfMemoryError = new System.OutOfMemoryException("OutOfMemoryError likely caused by the Sun VM Bug described in " + "https://issues.apache.org/jira/browse/LUCENE-1566; try calling FSDirectory.setReadChunkSize " + "with a a value smaller than the current chunks size (" + chunkSize + ")", e); throw outOfMemoryError; } } }
public override void ReadInternal(byte[] b, int offset, int len) { System.IO.MemoryStream bb; // Determine the ByteBuffer we should use if (b == buffer && 0 == offset) { // Use our own pre-wrapped byteBuf: System.Diagnostics.Debug.Assert(byteBuf != null); byteBuf.Position = 0; byteBuf.Capacity = len; bb = byteBuf; } else { if (offset == 0) { if (otherBuffer != b) { // Now wrap this other buffer; with compound // file, we are repeatedly called with its // buffer, so we wrap it once and then re-use it // on subsequent calls otherBuffer = b; // otherByteBuf = ByteBuffer.wrap(b); {{Aroush-2.9}} System.Diagnostics.Debug.Fail("Port issue:", "otherByteBuf = ByteBuffer.wrap(b)"); // {{Aroush-2.9}} } else otherByteBuf.Position = 0; otherByteBuf.Capacity = len; bb = otherByteBuf; } else { // Always wrap when offset != 0 bb = null; // bb = ByteBuffer.wrap(b, offset, len); {{Aroush-2.9}} System.Diagnostics.Debug.Fail("Port issue:", "bb = ByteBuffer.wrap(b, offset, len)"); // {{Aroush-2.9}} } } int readOffset = (int) bb.Position; int readLength = bb.Capacity - readOffset; System.Diagnostics.Debug.Assert(readLength == len); long pos = GetFilePointer(); try { while (readLength > 0) { int limit; if (readLength > chunkSize) { // LUCENE-1566 - work around JVM Bug by breaking // very large reads into chunks limit = readOffset + chunkSize; } else { limit = readOffset + readLength; } bb.Capacity = limit; int i = -1; // int i = channel.Read(bb, pos, limit); // {{Aroush-2.9}} must read from 'channel' into 'bb' System.Diagnostics.Debug.Fail("Port issue:", "channel.Read(bb, pos, limit)"); // {{Aroush-2.9}} if (i == - 1) { throw new System.IO.IOException("read past EOF"); } pos += i; readOffset += i; readLength -= i; } } catch (System.OutOfMemoryException e) { // propagate OOM up and add a hint for 32bit VM Users hitting the bug // with a large chunk size in the fast path. System.OutOfMemoryException outOfMemoryError = new System.OutOfMemoryException("OutOfMemoryError likely caused by the Sun VM Bug described in " + "https://issues.apache.org/jira/browse/LUCENE-1566; try calling FSDirectory.setReadChunkSize " + "with a a value smaller than the current chunk size (" + chunkSize + ")", e); throw outOfMemoryError; } }
public static void OutOfMemoryExceptionHandler(System.OutOfMemoryException e) { MessageBox.Show("OutOfMemoryException caught"); MessageBox.Show(e.Message); }
internal static Exception GetExceptionFromCOMException(DirectoryContext context, COMException e) { Exception exception; int errorCode = e.ErrorCode; string errorMessage = e.Message; // // Check if we can throw a more specific exception // if (errorCode == unchecked((int)0x80070005)) { // // Access Denied // exception = new UnauthorizedAccessException(errorMessage, e); } else if (errorCode == unchecked((int)0x8007052e)) { // // Logon Failure // exception = new AuthenticationException(errorMessage, e); } else if (errorCode == unchecked((int)0x8007202f)) { // // Constraint Violation // exception = new InvalidOperationException(errorMessage, e); } else if (errorCode == unchecked((int)0x80072035)) { // // Unwilling to perform // exception = new InvalidOperationException(errorMessage, e); } else if (errorCode == unchecked((int)0x80071392)) { // // Object already exists // exception = new ActiveDirectoryObjectExistsException(errorMessage, e); } else if (errorCode == unchecked((int)0x80070008)) { // // No Memory // exception = new OutOfMemoryException(); } else if ((errorCode == unchecked((int)0x8007203a)) || (errorCode == unchecked((int)0x8007200e)) || (errorCode == unchecked((int)0x8007200f))) { // // ServerDown/Unavailable/Busy // if (context != null) { exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, context.GetServerName()); } else { exception = new ActiveDirectoryServerDownException(errorMessage, e, errorCode, null); } } else { // // Wrap the exception in a generic OperationException // exception = new ActiveDirectoryOperationException(errorMessage, e, errorCode); } return exception; }
/// <summary> /// Displays an error message when OutOfMemoryException is thrown. /// </summary> /// <param name="ex">The exception</param> private static void ShowException(OutOfMemoryException ex) { PrepareToShow(); string errorMessage = Util.CombineMessageParts(SharedStrings.OUT_OF_MEMORY, ex.Source); ShowError(errorMessage, false); }
public static void Ctor(OutOfMemoryException aThis) { // }
public void OutOfMemory() { var ex = new OutOfMemoryException(); Assert.IsTrue(ex.IsCorruptedStateException()); }
// public static uint ERROR_LDAP_INVALID_CREDENTIALS = 49; //fix error CS0414: Warning as Error: is assigned but its value is never used // // This method maps some common COM Hresults to // existing clr exceptions // internal static Exception GetExceptionFromCOMException(COMException e) { Exception exception; int errorCode = e.ErrorCode; string errorMessage = e.Message; // // Check if we can throw a more specific exception // if (errorCode == unchecked((int)0x80070005)) { // // Access Denied // exception = new UnauthorizedAccessException(errorMessage, e); } else if (errorCode == unchecked((int)0x800708c5) || errorCode == unchecked((int)0x80070056) || errorCode == unchecked((int)0x8007052)) { // // Password does not meet complexity requirements or old password does not match or policy restriction has been enforced. // exception = new PasswordException(errorMessage, e); } else if (errorCode == unchecked((int)0x800708b0) || errorCode == unchecked((int)0x80071392)) { // // Principal already exists // exception = new PrincipalExistsException(errorMessage, e); } else if (errorCode == unchecked((int)0x8007052e)) { // // Logon Failure // exception = new AuthenticationException(errorMessage, e); } else if (errorCode == unchecked((int)0x8007202f)) { // // Constraint Violation // exception = new InvalidOperationException(errorMessage, e); } else if (errorCode == unchecked((int)0x80072035)) { // // Unwilling to perform // exception = new InvalidOperationException(errorMessage, e); } else if (errorCode == unchecked((int)0x80070008)) { // // No Memory // exception = new OutOfMemoryException(); } else if ((errorCode == unchecked((int)0x8007203a)) || (errorCode == unchecked((int)0x8007200e)) || (errorCode == unchecked((int)0x8007200f))) { exception = new PrincipalServerDownException(errorMessage, e, errorCode, null); } else { // // Wrap the exception in a generic OperationException // exception = new PrincipalOperationException(errorMessage, e, errorCode); } return exception; }
public void StripNestedAggregateExceptions() { _client.AddWrapperExceptions(typeof(AggregateException)); OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s"); NotSupportedException exception3 = new NotSupportedException("Forgot to implement this method"); AggregateException innerWrapper = new AggregateException(_exception, exception2); AggregateException wrapper = new AggregateException(innerWrapper, exception3); List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList(); Assert.AreEqual(3, exceptions.Count); Assert.Contains(_exception, exceptions); Assert.Contains(exception2, exceptions); Assert.Contains(exception3, exceptions); }
public void StripTargetInvocationExceptionAndAggregateException() { OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s"); AggregateException innerWrapper = new AggregateException(_exception, exception2); TargetInvocationException wrapper = new TargetInvocationException(innerWrapper); List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList(); Assert.AreEqual(2, exceptions.Count); Assert.IsTrue(exceptions.Contains(_exception)); Assert.IsTrue(exceptions.Contains(exception2)); }
//Creates a row against the date to database public void AddRowToDb(string date, string tin = "00:00", string tout = "00:00", string lin = "00:00", string lout = "00:00") { //Create a default entry DBRow tempp = new DBRow() { Date = date, TimeIn = tin, TimeOut = tout, LunchIn = lin, LunchOut = lout, ClockedTime = "00:00" //_version = new System.Data.Linq.Binary(bytes) }; //Remove all unknown changes //RefreshAndDiscardDbChanges(); //Insert the new row ChangeSet cs = database.GetChangeSet(); database.logentries.InsertOnSubmit(tempp); database.SubmitChanges(); //Check if successful! var readback = QueryRowInDb(date); if (readback == null) { OutOfMemoryException Expc = new OutOfMemoryException("Entry could not be made into the timelog database"); } }
private void HandleOutOfMemoryException(OutOfMemoryException oome) { log.WarnException( @"Failed to execute indexing because of an out of memory exception. Will force a full GC cycle and then become more conservative with regards to memory", oome); // On the face of it, this is stupid, because OOME will not be thrown if the GC could release // memory, but we are actually aware that during indexing, the GC couldn't find garbage to clean, // but in here, we are AFTER the index was done, so there is likely to be a lot of garbage. GC.Collect(GC.MaxGeneration); autoTuner.OutOfMemoryExceptionHappened(); }
void LockOnWeakId5() { OutOfMemoryException outOfMemory = new OutOfMemoryException(); lock(outOfMemory) {} }
public static string ExceptionToString(System.OutOfMemoryException e) { return(R._("System.OutOfMemoryExceptionが発生しました。\r\n何度も再発する場合は、report7zを送ってください。\r\nMessage:\r\n{0}\r\n{1}", e.ToString(), e.StackTrace)); }
public static void SaveException2(OutOfMemoryException e) { if (e.TargetSite.Name == "ThrowInvalidOperationException") return; if (e.Message.Contains("String reference not set")) return; Console.WriteLine(e); var dt = DateTime.Now; string date = dt.Month + "-" + dt.Day + "//"; if (!Directory.Exists(Application.StartupPath + ServerBase.Constants.UnhandledExceptionsPath)) Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath); if (!Directory.Exists(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date)) Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date); if (!Directory.Exists(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date + e.TargetSite.Name)) Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date + e.TargetSite.Name); string fullPath = Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date + e.TargetSite.Name + "\\"; string date2 = dt.Hour + "-" + dt.Minute; List<string> Lines = new List<string>(); Lines.Add("----Exception message----"); Lines.Add(e.Message); Lines.Add("----End of exception message----\r\n"); Lines.Add("----Stack trace----"); Lines.Add(e.StackTrace); Lines.Add("----End of stack trace----\r\n"); //Lines.Add("----Data from exception----"); //foreach (KeyValuePair<object, object> data in e.Data) // Lines.Add(data.Key.ToString() + "->" + data.Value.ToString()); //Lines.Add("----End of data from exception----\r\n"); File.WriteAllLines(fullPath + date2 + ".txt", Lines.ToArray()); }
/// <summary>Construct a wrapper around the original OutOfMemoryError.</summary> /// <remarks>Construct a wrapper around the original OutOfMemoryError.</remarks> /// <param name="cause">the original root cause.</param> public OutOfMemory(OutOfMemoryException cause) { Sharpen.Extensions.InitCause(this, cause); }
internal static Exception GetExceptionFromCOMException(DirectoryContext context, COMException e) { Exception activeDirectoryServerDownException; int errorCode = e.ErrorCode; string message = e.Message; if (errorCode != -2147024891) { if (errorCode != -2147023570) { if (errorCode != -2147016657) { if (errorCode != -2147016651) { if (errorCode != -2147019886) { if (errorCode != -2147024888) { if (errorCode == -2147016646 || errorCode == -2147016690 || errorCode == -2147016689) { if (context == null) { activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, null); } else { activeDirectoryServerDownException = new ActiveDirectoryServerDownException(message, e, errorCode, context.GetServerName()); } } else { activeDirectoryServerDownException = new ActiveDirectoryOperationException(message, e, errorCode); } } else { activeDirectoryServerDownException = new OutOfMemoryException(); } } else { activeDirectoryServerDownException = new ActiveDirectoryObjectExistsException(message, e); } } else { activeDirectoryServerDownException = new InvalidOperationException(message, e); } } else { activeDirectoryServerDownException = new InvalidOperationException(message, e); } } else { activeDirectoryServerDownException = new AuthenticationException(message, e); } } else { activeDirectoryServerDownException = new UnauthorizedAccessException(message, e); } return activeDirectoryServerDownException; }