| 1 | // Licensed to the .NET Foundation under one or more agreements.
|
|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
|---|
| 3 |
|
|---|
| 4 | // ReSharper disable RedundantUsingDirective
|
|---|
| 5 | // ReSharper disable VirtualMemberCallInConstructor
|
|---|
| 6 |
|
|---|
| 7 | using System;
|
|---|
| 8 | using System.ComponentModel;
|
|---|
| 9 | using System.Net;
|
|---|
| 10 | using System.Runtime.InteropServices;
|
|---|
| 11 | using System.Runtime.Serialization;
|
|---|
| 12 |
|
|---|
| 13 | namespace SpaceWizards.HttpListener
|
|---|
| 14 | {
|
|---|
| 15 | [Serializable]
|
|---|
| 16 | public class HttpListenerException : Win32Exception
|
|---|
| 17 | {
|
|---|
| 18 | #if !UNITY_NETFRAMEWORK
|
|---|
| 19 | public HttpListenerException() : base(Marshal.GetLastPInvokeError())
|
|---|
| 20 | {
|
|---|
| 21 | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
|
|---|
| 22 | }
|
|---|
| 23 | #endif
|
|---|
| 24 |
|
|---|
| 25 | public HttpListenerException(int errorCode) : base(errorCode)
|
|---|
| 26 | {
|
|---|
| 27 | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | public HttpListenerException(int errorCode, string message) : base(errorCode, message)
|
|---|
| 31 | {
|
|---|
| 32 | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | protected HttpListenerException(SerializationInfo serializationInfo, StreamingContext streamingContext)
|
|---|
| 36 | : base(serializationInfo, streamingContext)
|
|---|
| 37 | {
|
|---|
| 38 | if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}");
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | // the base class returns the HResult with this property
|
|---|
| 42 | // we need the Win32 Error Code, hence the override.
|
|---|
| 43 | public override int ErrorCode => NativeErrorCode;
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|