📄 exceptionhandler.cs
字号:
namespace Imps.Client.Core
{
using System;
using System.Net;
using System.Net.Sockets;
public class ExceptionHandler
{
private const string TwoIntString = "{0}{1}";
public static int HandleSocketException(SocketException sEx)
{
if (sEx == null)
{
return 0x6d6;
}
int num = 750;
SocketError error = sEx.get_SocketErrorCode();
if (error <= 0x2753)
{
switch (error)
{
case -1:
num = 0x2e2;
goto Label_0386;
case 0:
num = 740;
goto Label_0386;
case 0x3e3:
num = 730;
goto Label_0386;
case 0x3e4:
case 0x2715:
case 0x2716:
case 0x2717:
case 0x2718:
case 0x2719:
case 0x271a:
case 0x271b:
case 0x271c:
case 0x271f:
case 0x2720:
case 0x2721:
case 0x2722:
case 0x2723:
case 0x2724:
case 0x2725:
case 0x2727:
case 0x2729:
case 0x272a:
case 0x272b:
case 0x272c:
case 0x272d:
case 0x272e:
case 0x272f:
case 0x2730:
case 0x2731:
case 0x2732:
case 0x274b:
case 0x274e:
case 0x274f:
case 0x2752:
goto Label_0386;
case 0x3e5:
num = 0x2ce;
goto Label_0386;
case 0x2714:
num = 0x2cc;
goto Label_0386;
case 0x271d:
num = 0x2bd;
goto Label_0386;
case 0x271e:
num = 0x2c7;
goto Label_0386;
case 0x2726:
num = 0x2cd;
goto Label_0386;
case 0x2728:
num = 0x2e7;
goto Label_0386;
case 0x2733:
num = 0x2eb;
goto Label_0386;
case 0x2734:
num = 0x2cb;
goto Label_0386;
case 0x2735:
num = 0x2c1;
goto Label_0386;
case 0x2736:
num = 0x2d9;
goto Label_0386;
case 0x2737:
num = 0x2c5;
goto Label_0386;
case 0x2738:
num = 720;
goto Label_0386;
case 0x2739:
num = 0x2e0;
goto Label_0386;
case 0x273a:
num = 0x2df;
goto Label_0386;
case 0x273b:
num = 0x2de;
goto Label_0386;
case 0x273c:
num = 0x2e3;
goto Label_0386;
case 0x273d:
num = 0x2db;
goto Label_0386;
case 0x273e:
num = 0x2dd;
goto Label_0386;
case 0x273f:
num = 0x2bf;
goto Label_0386;
case 0x2740:
num = 0x2be;
goto Label_0386;
case 0x2741:
num = 0x2c0;
goto Label_0386;
case 0x2742:
num = 0x2d1;
goto Label_0386;
case 0x2743:
num = 0x2d3;
goto Label_0386;
case 0x2744:
num = 0x2d2;
goto Label_0386;
case 0x2745:
num = 0x2c2;
goto Label_0386;
case 0x2746:
num = 0x2c4;
goto Label_0386;
case 0x2747:
num = 0x2d4;
goto Label_0386;
case 0x2748:
num = 0x2cf;
goto Label_0386;
case 0x2749:
num = 0x2d7;
goto Label_0386;
case 0x274a:
num = 0x2e1;
goto Label_0386;
case 0x274c:
num = 0x2e6;
goto Label_0386;
case 0x274d:
num = 0x2c3;
goto Label_0386;
case 0x2750:
num = 0x2c8;
goto Label_0386;
case 0x2751:
num = 0x2ca;
goto Label_0386;
case 0x2753:
num = 0x2dc;
goto Label_0386;
}
}
else if (error <= 0x2775)
{
switch (error)
{
case 0x276b:
num = 0x2e5;
goto Label_0386;
case 0x276c:
num = 0x2ea;
goto Label_0386;
case 0x276d:
num = 0x2d8;
goto Label_0386;
case 0x2775:
num = 710;
goto Label_0386;
}
}
else
{
switch (error)
{
case 0x2af9:
num = 0x2c9;
goto Label_0386;
case 0x2afa:
num = 0x2e8;
goto Label_0386;
case 0x2afb:
num = 0x2d6;
goto Label_0386;
case 0x2afc:
num = 0x2d5;
goto Label_0386;
case 0x277d:
num = 0x2e9;
goto Label_0386;
}
}
Label_0386:
int.TryParse(string.Format("{0}{1}", "1", num.ToString()), ref num);
return num;
}
public static int HandleWebException(WebException wEx)
{
if (wEx == null)
{
return 0x65d;
}
HttpWebResponse response = wEx.Response as HttpWebResponse;
int statusCode = 630;
if (response != null)
{
try
{
statusCode = (int) response.StatusCode;
}
catch
{
}
}
else
{
switch (wEx.Status)
{
case WebExceptionStatus.Success:
statusCode = 620;
goto Label_0148;
case WebExceptionStatus.NameResolutionFailure:
statusCode = 0x259;
goto Label_0148;
case WebExceptionStatus.ConnectFailure:
statusCode = 0x25a;
goto Label_0148;
case WebExceptionStatus.ReceiveFailure:
statusCode = 0x265;
goto Label_0148;
case WebExceptionStatus.SendFailure:
statusCode = 0x25e;
goto Label_0148;
case WebExceptionStatus.PipelineFailure:
statusCode = 0x263;
goto Label_0148;
case WebExceptionStatus.RequestCanceled:
statusCode = 0x266;
goto Label_0148;
case WebExceptionStatus.ProtocolError:
statusCode = 0x264;
goto Label_0148;
case WebExceptionStatus.ConnectionClosed:
statusCode = 0x25f;
goto Label_0148;
case WebExceptionStatus.TrustFailure:
statusCode = 0x26a;
goto Label_0148;
case WebExceptionStatus.SecureChannelFailure:
statusCode = 0x25d;
goto Label_0148;
case WebExceptionStatus.ServerProtocolViolation:
statusCode = 0x269;
goto Label_0148;
case WebExceptionStatus.KeepAliveFailure:
statusCode = 0x260;
goto Label_0148;
case WebExceptionStatus.Pending:
statusCode = 610;
goto Label_0148;
case WebExceptionStatus.Timeout:
statusCode = 0x25c;
goto Label_0148;
case WebExceptionStatus.ProxyNameResolutionFailure:
statusCode = 0x25b;
goto Label_0148;
case WebExceptionStatus.UnknownError:
statusCode = 0x26b;
goto Label_0148;
case WebExceptionStatus.MessageLengthLimitExceeded:
statusCode = 0x261;
goto Label_0148;
case (WebExceptionStatus.UnknownError | WebExceptionStatus.ConnectFailure):
statusCode = 0x26d;
goto Label_0148;
case (WebExceptionStatus.MessageLengthLimitExceeded | WebExceptionStatus.ConnectFailure):
statusCode = 0x267;
goto Label_0148;
case (WebExceptionStatus.UnknownError | WebExceptionStatus.SendFailure):
statusCode = 0x268;
goto Label_0148;
}
}
Label_0148:
int.TryParse(string.Format("{0}{1}", "1", statusCode.ToString()), ref statusCode);
return statusCode;
}
public static bool IsRetryNeeded(WebException wEx)
{
if (wEx == null)
{
return false;
}
HttpWebResponse response = wEx.Response as HttpWebResponse;
if (response != null)
{
int statusCode = (int) response.StatusCode;
return ((statusCode >= 400) && (statusCode <= 0x1f9));
}
switch (wEx.Status)
{
case WebExceptionStatus.Success:
case WebExceptionStatus.NameResolutionFailure:
case WebExceptionStatus.ReceiveFailure:
case WebExceptionStatus.SendFailure:
case WebExceptionStatus.ConnectionClosed:
case WebExceptionStatus.SecureChannelFailure:
case WebExceptionStatus.KeepAliveFailure:
case WebExceptionStatus.Timeout:
case WebExceptionStatus.ProxyNameResolutionFailure:
return true;
case WebExceptionStatus.ConnectFailure:
case WebExceptionStatus.PipelineFailure:
case WebExceptionStatus.RequestCanceled:
case WebExceptionStatus.ProtocolError:
case WebExceptionStatus.TrustFailure:
case WebExceptionStatus.ServerProtocolViolation:
case WebExceptionStatus.Pending:
case WebExceptionStatus.UnknownError:
case WebExceptionStatus.MessageLengthLimitExceeded:
case (WebExceptionStatus.UnknownError | WebExceptionStatus.ConnectFailure):
case (WebExceptionStatus.MessageLengthLimitExceeded | WebExceptionStatus.ConnectFailure):
case (WebExceptionStatus.UnknownError | WebExceptionStatus.SendFailure):
return false;
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -