public static int Main(String[] args) { Thread mv_Thread; ExternalException ee = new ExternalException(); ExitCode = (100); for (int i = 0; i < 2; i++) { mv_Thread = new Thread(new ThreadStart(ee.runtest)); try { if (i == 0) { mv_Thread.Name = "" + i; } else { mv_Thread.Name = i + ""; } mv_Thread.Start(); } catch (Exception) { Console.Out.WriteLine("Exception was caught in main"); } } return ExitCode; }
[Test] // ctor (string, int) public void Constructor4() { ExternalException ex; string msg = "ERROR"; ex = new ExternalException(msg, int.MinValue); Assert.AreEqual(int.MinValue, ex.ErrorCode, "#A1"); Assert.IsNull(ex.InnerException, "#A2"); Assert.AreSame(msg, ex.Message, "#A3"); ex = new ExternalException((string)null, int.MaxValue); Assert.AreEqual(int.MaxValue, ex.ErrorCode, "#B1"); Assert.IsNull(ex.InnerException, "#B2"); Assert.IsNotNull(msg, ex.Message, "#B3"); Assert.AreEqual(new ExternalException(null).Message, ex.Message, "#B4"); ex = new ExternalException(msg, 0); Assert.AreEqual(0, ex.ErrorCode, "#C1"); Assert.IsNull(ex.InnerException, "#C2"); Assert.AreSame(msg, ex.Message, "#C3"); ex = new ExternalException(string.Empty, 0); Assert.AreEqual(0, ex.ErrorCode, "#D1"); Assert.IsNull(ex.InnerException, "#D2"); Assert.IsNotNull(ex.Message, "#D3"); Assert.AreEqual(string.Empty, ex.Message, "#D4"); }
public static ExternalException /*!*/ Factory(RubyClass /*!*/ self, [DefaultProtocol] MutableString message) { ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error")); RubyExceptionData.InitializeException(result, message); return(result); }
public object MarshalNativeToManaged(IntPtr pNativeData) { if (pNativeData == IntPtr.Zero) { return(null); } string function = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_failed_function(pNativeData)); string args = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_failed_args(pNativeData)); string message = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_error_message(pNativeData)); ExceptionType type = NativeMethods.rs2_get_librealsense_exception_type(pNativeData); var inner = new ExternalException($"{function}({args})"); switch (type) { case ExceptionType.NotImplemented: throw new NotImplementedException(message, inner); case ExceptionType.WrongApiCallSequence: throw new InvalidOperationException(message, inner); case ExceptionType.InvalidValue: throw new ArgumentException(message, inner); case ExceptionType.Io: throw new System.IO.IOException(message, inner); default: throw new Exception(message, inner); } }
[Test] // ctor (string, Exception) public void Constructor3() { ExternalException ex; string msg = "ERROR"; Exception inner = new Exception(); ex = new ExternalException(msg, inner); Assert.AreEqual(-2147467259, ex.ErrorCode, "#A1"); Assert.AreSame(inner, ex.InnerException, "#A2"); Assert.AreSame(msg, ex.Message, "#A3"); ex = new ExternalException((string)null, inner); Assert.AreEqual(-2147467259, ex.ErrorCode, "#B1"); Assert.AreSame(inner, ex.InnerException, "#B2"); Assert.IsNotNull(msg, ex.Message, "#B3"); Assert.AreEqual(new ExternalException(null).Message, ex.Message, "#B4"); ex = new ExternalException(msg, (Exception)null); Assert.AreEqual(-2147467259, ex.ErrorCode, "#C1"); Assert.IsNull(ex.InnerException, "#C2"); Assert.AreSame(msg, ex.Message, "#C3"); ex = new ExternalException(string.Empty, (Exception)null); Assert.AreEqual(-2147467259, ex.ErrorCode, "#D1"); Assert.IsNull(ex.InnerException, "#D2"); Assert.IsNotNull(ex.Message, "#D3"); Assert.AreEqual(string.Empty, ex.Message, "#D4"); }
/// <summary> /// Called when there's a compiler error. /// </summary> /// <param name="error"></param> /// <returns></returns> public bool OnCompilerError(IVsaError error) { _exception = new ExternalException(error.Description, error.Number); _exception.Source = error.LineText; return(true); }
public static THResult?ToHResult <THResult> (this ExternalException ex) where THResult : struct { if (Enum.IsDefined(typeof(THResult), ex.ErrorCode)) { return((THResult?)Enum.ToObject(typeof(THResult), ex.ErrorCode)); } return(null); }
public static void Ctor_String() { string message = "Created ExternalException"; ExternalException exception = new ExternalException(message); Assert.Equal(COR_E_EXTERNAL, exception.HResult); Assert.Null(exception.InnerException); Assert.Same(message, exception.Message); }
public static void Ctor_String_int() { string msg = "Created ExternalException"; int errorCode = -2000607220; ExternalException exception = new ExternalException(msg, errorCode); Assert.Equal(msg, exception.Message); Assert.Equal(COR_E_EXTERNAL, exception.HResult); }
public static void Ctor_Empty() { ExternalException exception = new ExternalException(); Assert.Null(exception.InnerException); Assert.NotNull(exception.Message); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_EXTERNAL, exception.HResult); }
private static void ThrowIfFailed(int hr) { if (hr != 0) { ExternalException exception = new ExternalException(System.Windows.Forms.SR.GetString("ClipboardOperationFailed"), hr); throw exception; } }
[Test] // ctor () public void Constructor0() { ExternalException ex = new ExternalException(); Assert.AreEqual(-2147467259, ex.ErrorCode, "#1"); Assert.IsNull(ex.InnerException, "#2"); Assert.IsNotNull(ex.Message, "#3"); Assert.IsTrue(ex.Message.IndexOf(ex.GetType().FullName) == -1, "#4"); }
public static void Ctor_String_Exception() { string message = "Created ExternalException"; var innerException = new Exception("Created inner exception"); ExternalException exception = new ExternalException(message, innerException); Assert.Equal(message, exception.Message); Assert.Equal(innerException, exception.InnerException); Assert.Equal(COR_E_EXTERNAL, exception.HResult); }
// END - WHIDBEY ADDITIONS --> private static void ThrowIfFailed(int hr) { // if (hr != 0) { ExternalException e = new ExternalException(SR.ClipboardOperationFailed, hr); throw e; } }
private static void ThrowIfFailed(int hr) { // CONSIDER : This should use a "FAILED" type function... if (hr != 0) { ExternalException e = new ExternalException(SR.GetString(SR.ClipboardOperationFailed), hr); throw e; } }
public static void Ctor_String() { string message = "Created ExternalException"; ExternalException exception = new ExternalException(message); Assert.Equal(COR_E_EXTERNAL, exception.HResult); Assert.Null(exception.InnerException); Assert.Same(message, exception.Message); }
public static void Ctor_String_int() { string msg = "Created ExternalException"; int errorCode = -2000607220; ExternalException exception = new ExternalException(msg, errorCode); Assert.Equal(msg, exception.Message); Assert.Equal(errorCode, exception.HResult); }
public static void Ctor_Empty() { ExternalException exception = new ExternalException(); Assert.Null(exception.InnerException); Assert.NotNull(exception.Message); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_EXTERNAL, exception.HResult); }
public static ExternalException /*!*/ Factory(RubyClass /*!*/ self, [DefaultProtocol] MutableString message) { #if SILVERLIGHT || WIN8 || WP75 ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error")); #else ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error"), int.MinValue); #endif RubyExceptionData.InitializeException(result, message); return(result); }
public static void Ctor_String_Exception() { string message = "Created ExternalException"; var innerException = new Exception("Created inner exception"); ExternalException exception = new ExternalException(message, innerException); Assert.Equal(message, exception.Message); Assert.Equal(innerException, exception.InnerException); Assert.Equal(COR_E_EXTERNAL, exception.HResult); }
public static ExternalException /*!*/ Factory(RubyClass /*!*/ self, int errorCode) { // TODO: var message = MutableString.Create("system error #" + errorCode, RubyEncoding.UTF8); ExternalException result = new ExternalException(RubyExceptions.MakeMessage(ref message, "unknown error")); RubyExceptionData.InitializeException(result, message); return(result); }
/// <summary> /// Connects to the server and browses for top level nodes. /// </summary> internal void Connect() { // connect to server if not already connected. if (Tag.IsConnected) { return; } try { Application.UseWaitCursor = true; string _message = $"Connecting to {Tag.Name} at {Tag.Url} with prefered specyfication {Tag.PreferedSpecyfication}"; AssemblyTraceEvent.Tracer.TraceInformation(_message); Tag.Connect(m_ConnectData); _message = $"Connecting to {Tag.Name} at succided"; AssemblyTraceEvent.Tracer.TraceInformation(_message); Tag.ServerShutdown += new Opc.ServerShutdownEventHandler(server_ServerShutdown); m_SupportedLocales = Tag.GetSupportedLocales(); if (!string.IsNullOrEmpty(m_Locale)) { Tag.SetLocale(m_Locale); } Tag.SetResultFilters((int)m_Filter); foreach (SubscriptionTreeNodeSession node in Nodes) { node.Subscribe(); } LastEception = null; State = state.connected; _message = $"Connecting to {Tag.Name} at succided"; AssemblyTraceEvent.Tracer.TraceInformation(_message); } catch (Opc.ConnectFailedException _ex) { ReportException(_ex); string _exMessage = $"Connecting to {Tag.Name} failed with exception {_ex.Message} by application {_ex.Source} at {_ex.StackTrace}"; AssemblyTraceEvent.Tracer.TraceInformation(_exMessage); ExternalException _inner = _ex.InnerException == null ? null : _ex.InnerException as ExternalException; if (_inner == null) { return; } _exMessage = $"Connecting to {Tag.Name} failed with external exception {_inner.Message} by application {_inner.Source} at {_inner.StackTrace} with error code {_inner.ErrorCode}"; AssemblyTraceEvent.Tracer.TraceInformation(_exMessage); } catch (Exception _ex) { string _exMessage = $"Connecting to {Tag.Name} failed with exception {_ex.Message} by application {_ex.Source} at {_ex.StackTrace}"; AssemblyTraceEvent.Tracer.TraceEvent(TraceEventType.Error, 199, _exMessage); ReportException(_ex); } finally { Application.UseWaitCursor = false; } }
private static Exception SafeCreateMatroshika(ExternalException inner) { var result = GetMatroshika(inner); if (result != null) { _exceptionHResultProperty.SetValue(result, Marshal.GetHRForException(inner), null); } return(result); }
/// <summary> /// Creates an XboxInputException derived type that maps to the HResult of the ExternalException. /// </summary> /// <param name="message">The message.</param> /// <param name="innerException">The inner exception.</param> /// <param name="xboxName">The name of the Xbox.</param> /// <param name="gamepadId">A gamepads Id.</param> /// <returns>An XboxInputException derived type that maps to the HResult of the ExternalException.</returns> public static Exception Create(string message, ExternalException innerException, string xboxName, ulong gamepadId) { if (innerException == null) { throw new ArgumentNullException("innerException"); } string errorMessage = string.Format(CultureInfo.InvariantCulture, "{0}. Reason: {1}", message, GetWin32ErrorMessage(innerException.ErrorCode)); return(new XboxInputException(errorMessage, innerException, xboxName, gamepadId)); }
/// <summary> /// Called whenever SimConnect generates an error /// </summary> /// <param name="sender">SimConnect</param> /// <param name="e">Exception containing SimConnect error data</param> private void SimError(object sender, ExternalException e) { var errorId = Convert.ToInt32(e.Data["dwID"]); var sendId = Convert.ToInt32(e.Data["dwSendID"]); var indexId = Convert.ToDouble(e.Data["dwIndex"]); var exceptionId = Convert.ToInt32(e.Data["dwException"]); var exceptionType = (string)e.Data["exceptionType"]; var errorMessage = string.Format("\terrorId: {0}\r\n\tsendId: {1}\r\n\tindexId: {2}\r\n\texceptionId: {3}\r\n\texceptionType: {4}", errorId, sendId, indexId, exceptionId, exceptionType); UpdateErrorText(txtErrors, string.Format("\r\n{0:HH:mm:ss} ({1}) {2}\r\nData:\r\n{3}", DateTime.Now, exceptionType, e.Message, errorMessage)); //throw e; }
private static Exception TryPopulateException(string header, Exception exception, JObject data) { if (data.TryGetValue("ExceptionDetail", out var info)) { var ex = new ExternalException(string.Join(" ", header, info["Message"]?.Value <string>()), (info["HResult"].HasValues ? info["HResult"].Value <int>() : -1)) { Source = info["Source"]?.Value <string>() }; return(ex); } return(new TextException(header)); }
public async Task Invoke(HttpContext context) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var exceptionFeature = context.Features.Get <IExceptionHandlerFeature>(); var ex = exceptionFeature?.Error; if (ex == null) { return; } HttpResponseMessage hrm; ExceptionResponse er = new ExceptionResponse(); //string contentMessage = ""; try { hrm = ((HttpResponseException)ex).Response; er = hrm.ExceptionResponse(); //contentMessage = await hrm.Content.ReadAsStringAsync(); } catch { } if (er.Message == null) { er.StatusCode = HttpStatusCode.InternalServerError; er.Message = ex.Message; er.Source = ex.Source; try { ExternalException ee = (ExternalException)ex; er.ErrorCode = ee.ErrorCode; } catch { } er.StackTrace = ex.StackTrace; } context.Response.StatusCode = (int)er.StatusCode; context.Response.ContentType = "application/json"; using (var writer = new StreamWriter(context.Response.Body)) { //new JsonSerializer().Serialize(writer, er); string jsondata = JsonConvert.SerializeObject(er); string jsonFormatted = JValue.Parse(jsondata).ToString(Formatting.Indented); jsonFormatted = jsonFormatted.Replace("\\r\\n", "\n"); writer.Write(jsonFormatted); await writer.FlushAsync().ConfigureAwait(false); } }
public void TestExternalException() { var value = new ExternalException("Message", 12345); try { ExceptionDispatchInfo.Capture(value).Throw(); } catch (ExternalException ex) { Assert.That(ex, Is.Not.SameAs(value)); Assert.That(ex.ErrorCode, Is.EqualTo(value.ErrorCode)); } }
static string Format(Exception ex) { try { string msg = ex.GetType().FullName + ": " + ex.Message + Environment.NewLine + ex.StackTrace; ExternalException nativeEx = ex as ExternalException; if (nativeEx == null) { return(msg); } return(msg + Environment.NewLine + "HRESULT: " + nativeEx.ErrorCode); } catch (Exception) { return(""); } }
/// <summary> /// Compiles the script /// </summary> /// <returns><b>true</b> if compilation was successful, otherwise <b>false</b>.</returns> public bool Compile() { if (!_isInitialized) { InitializeEngine(); } _exception = null; bool success = _engine.Compile(); if (!success) { throw _exception; } return(success); }
private Exception HandleCommunicationError(ExternalException ex) { //TODO: not all RPC errors means this - can fail in local memory and thread inside RPC - should interpret accordingly var oldState = State; setState(CommunicationState.Faulted); switch (oldState) { case CommunicationState.Created: return(new EndpointNotFoundException(string.Format("Failed to connect to {0}", _router._address))); case CommunicationState.Opened: return(new CommunicationException(string.Format("Failed to request {0}", _router._address))); } return(ex); }
public static int Main(String [] args) { Thread mv_Thread; String str = "Done"; ExternalException ee = new ExternalException(); for (int i = 0 ; i < 10; i++){ mv_Thread = new Thread(new ThreadStart(ee.runtest)); try { mv_Thread.Start(); } catch (Exception ){ Console.WriteLine("Exception was caught in main"); } } Console.WriteLine(str); return retVal; }
// SocketException을 처리하는 메소드. private static void HandleException(ExternalException e) { var errorCode = (SocketError)e.ErrorCode; Debug.LogAssertion(e.Message); if (errorCode == SocketError.ConnectionAborted || errorCode == SocketError.Disconnecting || errorCode == SocketError.HostDown || errorCode == SocketError.Shutdown || errorCode == SocketError.SocketError || errorCode == SocketError.ConnectionReset) { // TODO :: Close Connect 알림을 서버에 던짐. } }
// Test the ExternalException class. public void TestExternalException() { // Check the three main exception constructors. ExceptionTester.CheckMain (typeof(ExternalException), unchecked((int)0x80004005)); // Test the fourth constructor. ExternalException e = new ExternalException ("foobar", 0x0BADBEEF); AssertEquals("COM (1)", "foobar", e.Message); AssertEquals("COM (2)", 0x0BADBEEF, e.ErrorCode); // Test that the error code is zero by default. e = new ExternalException("foobar"); AssertEquals("COM (3)", "foobar", e.Message); AssertEquals("COM (4)", 0, e.ErrorCode); }
// Test the ExternalException class. public void TestExternalException() { // Check the three main exception constructors. ExceptionTester.CheckMain (typeof(ExternalException), unchecked ((int)0x80004005)); // Test the fourth constructor. ExternalException e = new ExternalException ("foobar", 0x0BADBEEF); AssertEquals("COM (1)", "foobar", e.Message); AssertEquals("COM (2)", 0x0BADBEEF, e.ErrorCode); // Test that the error code is zero by default. e = new ExternalException("foobar"); AssertEquals("COM (3)", "foobar", e.Message); AssertEquals("COM (4)", 0, e.ErrorCode); }
/// <summary> /// Gets the name of the error by translating the error code into it's corresponding enumeration. /// </summary> /// <param name="externalException">The external exception.</param> /// <returns> /// Returns the enumeration of the error code otherwise <c>UNSPECIFIED FAILURE</c> is returned. /// </returns> public static string GetErrorName(this ExternalException externalException) { if (Enum.IsDefined(typeof(fdoError), externalException.ErrorCode)) { return(Enum.GetName(typeof(fdoError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriNetworkErrors), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriNetworkErrors), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriGeometryError), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriGeometryError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(dimError), externalException.ErrorCode)) { return(Enum.GetName(typeof(dimError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(annoError), externalException.ErrorCode)) { return(Enum.GetName(typeof(annoError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriCoreErrorReturnCodes), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriCoreErrorReturnCodes), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriDataConverterError), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriDataConverterError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriSpatialReferenceError), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriSpatialReferenceError), externalException.ErrorCode)); } if (Enum.IsDefined(typeof(esriRepresentationDrawingError), externalException.ErrorCode)) { return(Enum.GetName(typeof(esriRepresentationDrawingError), externalException.ErrorCode)); } Win32Exception e = new Win32Exception(externalException.ErrorCode); return(e.Message.ToUpper(CultureInfo.CurrentCulture)); }
public static int Main(String [] args) { Thread mv_Thread; String str = "Done"; ExternalException ee = new ExternalException(); for (int i = 0; i < 10; i++) { mv_Thread = new Thread(new ThreadStart(ee.runtest)); try { mv_Thread.Start(); } catch (Exception) { Console.WriteLine("Exception was caught in main"); } } Console.WriteLine(str); return(retVal); }
/// <include file='doc\NativeMethods.uex' path='docs/doc[@for="NativeMethods.ConnectionPointCookie.ConnectionPointCookie1"]/*' /> /// <devdoc> /// Creates a connection point to of the given interface type. /// which will call on a managed code sink that implements that interface. /// </devdoc> public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException, out bool connected){ connected = false; Exception ex = null; if (source is UnsafeNativeMethods.IConnectionPointContainer) { UnsafeNativeMethods.IConnectionPointContainer cpc = (UnsafeNativeMethods.IConnectionPointContainer)source; try { Guid tmp = eventInterface.GUID; if (cpc.FindConnectionPoint(ref tmp, out connectionPoint) != NativeMethods.S_OK) { connectionPoint = null; } } catch (Exception) { connectionPoint = null; } if (connectionPoint == null) { ex = new ArgumentException(SR.GetString(SR.ConnPointSourceIF, eventInterface.Name )); } else if (sink == null || !eventInterface.IsInstanceOfType(sink)) { ex = new InvalidCastException(SR.GetString(SR.ConnPointSinkIF)); } else { int hr = connectionPoint.Advise(sink, ref cookie); if (hr != S_OK) { cookie = 0; Marshal.ReleaseComObject(connectionPoint); connectionPoint = null; ex = new ExternalException(SR.GetString(SR.ConnPointAdviseFailed, eventInterface.Name, hr )); } else { connected = true; } } } else { ex = new InvalidCastException(SR.GetString(SR.ConnPointSourceIF, "IConnectionPointContainer")); } if (throwException && (connectionPoint == null || cookie == 0)) { if (connectionPoint != null) { Marshal.ReleaseComObject(connectionPoint); } if (ex == null) { throw new ArgumentException(SR.GetString(SR.ConnPointCouldNotCreate, eventInterface.Name )); } else { throw ex; } } #if DEBUG new EnvironmentPermission(PermissionState.Unrestricted).Assert(); try { callStack = Environment.StackTrace; } finally { System.Security.CodeAccessPermission.RevertAssert(); } #endif }