我正在创建一个C#应用程序,并尝试在适当时利用自定义异常.我在这里和MSDN设计指南中查看了其他问题,但没有遇到任何具体的问题,我在这里想知道.
如何组织自定义例外的最佳做法是什么?
例如,我有一个类Disk抛出一个InvalidDiskException.Disk是唯一抛出此异常的类.
目前,我有异常嵌套在Disk.cs文件中,如下所示:
Disk.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrganizingExceptionsInCSharp
{
class Disk
{
[Serializable]
public class InvalidDiskException : Exception
{
public InvalidDiskException() { }
public InvalidDiskException(string message) : base(message) { }
public InvalidDiskException(string message, Exception innerException) : base(message, innerException) { }
}
//
// Code that throws the exception.
//
}
}
Run Code Online (Sandbox Code Playgroud)
是否应该将异常定义在与磁盘相同的级别(即未嵌套在内)?该异常应该嵌套在磁盘中,但保留它自己的部分文件吗?可能还有其他更好的选择吗?如果还有其他我没有想过的考虑因素,请告诉我.
我有一台装有 CopSSH 的 Windows Server 2008 机器 (iis7)。为了连接到它,我有一台安装了 Mercurial 1.5.1(和 TortoiseHg)的 Windows 7 机器。
我可以使用 PuTTY 与非标准 ssh 端口和 .ppk 文件连接到服务器就好了。所以我知道服务器可以通过 SSH 连接。
接下来,我想使用 CLI 通过 hg clone 进行连接以获取私有存储库。我在别处看到你需要在你的 mercurial.ini 文件中配置 ssh,所以我的 mercurial.ini 有一行:ssh = plink.exe -ssh -C -l username -P #### -i "C:/Program Files/PuTTY/Key Files/KyleKey.ppk"
注意:
username填写的是我通过 copSSH 设置的用户名。
####填充了我为 copSSH 定义的非标准 ssh 端口。
我尝试执行命令,hg clone ssh://inthom.com但出现此错误:
remote: bash: inthom.com: command not found
abort: no suitable response from remote hg!
看起来 hg 或 plink …