这真的非常让我感到高兴,所以我希望有人可以给我一个合理的理由来解释为什么事情就像他们一样.
NotImplementedException. 你拉我的腿吧?
不,我不打算通过说,"坚持,方法实现 - 它会抛出NotImplementedException".是的,没错,你必须实现抛出NotImplementedException的方法(不像C++中的纯虚函数调用 - 现在才有意义!).虽然这很可笑,但在我看来还有一个更严重的问题.
我只是想知道,在存在NotImplementedException的情况下,任何人都可以用.Net做任何事情?您是否希望使用try catch块包装每个抽象方法调用以防止可能未实现的方法?如果你遇到这样的例外,你应该怎么做呢?
我认为没有办法测试一个方法是否在没有调用的情况下实际实现.因为调用它可能有副作用,我不能提前完成所有检查,然后运行我的算法.我必须运行我的算法,捕获NotImplementedExceptions以及一些如何将我的应用程序回滚到一些理智的状态.
这很疯狂.狂.疯.所以问题是: 为什么存在NotImplementedException?
作为先发制人的罢工,我不希望任何人回应,"因为设计师需要将其放入自动生成的代码中." 这太可怕了.在您提供实现之前,我宁愿不编译自动生成的代码.例如,自动生成的实现可能是"throw NotImplementedException;" 其中未定义NotImplementedException!
有没有人捕获并处理过NotImplementedException?你有没有在你的代码中留下NotImplementedException?如果是这样,这是代表定时炸弹(即,你不小心将它留在那里),还是设计缺陷(该方法不应该实施,永远不会被调用)?
我也非常怀疑NotSupportedException ...不支持?什么?如果它不受支持,为什么它是你的界面的一部分?微软的任何人都可以拼写不正当的继承吗?但是如果我对这个问题没有太多的滥用,我可能会提出另一个问题.
附加信息:
这是一个有趣的读物.
似乎与Brad Abrams有一个强烈的一致意见,"NotImplementedException是针对尚未实现的功能,但实际上应该(并且将会是).类似于在构建类时可能开始的内容,获取所有方法抛出NotImplementedException,然后用实际代码刷新它们......"
来自Jared Parsons的注释非常弱,应该可以忽略:NotImplementedException:当类型由于任何其他原因没有实现方法时抛出此异常.
在MSDN上的主题更弱,只是说,"当一个请求的方法或操作未实现时引发的异常."
.net exception-handling exception notimplementedexception notsupportedexception
我正在实现一个自定义集合实现,可以是readonly或非readonly; 也就是说,所有改变集合的方法都会调用一个与道德相当的函数:
private void ThrowIfReadOnly() {
if (this.isReadOnly)
throw new SomeException("Cannot modify a readonly collection.");
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我不确定应该使用哪种NotSupportedException
或者InvalidOperationException
我应该使用.
.net c# exception invalidoperationexception notsupportedexception
我更新了我的项目以使用Automapper 3.0.0,现在我的TFS构建没有成功.错误如下:
" ... System.PlatformNotSupportedException:System.PlatformNotSupportedException:此平台上的IMapperRegistry不支持此类型. "
有没有人可以帮我解决这个问题.与此同时,我将恢复到以前的版本,因为那个似乎工作正常.
我在尝试stream.Length发送到我的WCF方法的Stream对象时收到错误.
Unhandled Exception!
Error ID: 0
Error Code: Unknown
Is Warning: False
Type: System.NotSupportedException
Stack: at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.get_Length()
Run Code Online (Sandbox Code Playgroud)
你如何得到流的长度?任何例子?
在以下发布的代码中我在android中"在这个语言级别不支持尝试使用资源"的问题,我试图将语言设置为7但是它仍然不断给我相同的示例加上它一直给我选项改为语言7.
public String ReadFile(String fileName) {
try (BufferedReader br = new BufferedReader(new FileReader(fileName+".txt"))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
return everything;
} catch (FileNotFoundException ex) {
Logger.getLogger(SaveNLoadRank.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SaveNLoadRank.class.getName()).log(Level.SEVERE, null, ex);
}
return "1";
}
Run Code Online (Sandbox Code Playgroud) 是否有更好/更准确/更严格的方法/方法来确定URL是否格式正确?
使用:
bool IsGoodUrl = Uri.IsWellFormedUriString(url, UriKind.Absolute);
Run Code Online (Sandbox Code Playgroud)
不抓住一切.如果我输入htttp://www.google.com
并运行该过滤器,它就会通过.然后我NotSupportedException
打电话给我WebRequest.Create
.
这个错误的网址也会使它超过以下代码(这是我能找到的唯一其他过滤器):
Uri nUrl = null;
if (Uri.TryCreate(url, UriKind.Absolute, out nUrl))
{
url = nUrl.ToString();
}
Run Code Online (Sandbox Code Playgroud) 当我尝试调用Find()时,我不断收到此错误
public void findTxt(string text)
{
BindingSource src = new BindingSource();
src.DataSource = dataGridView1.DataSource;
src.Position = src.Find("p_Name", text); // Specified method is not supported
if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() == text)
{
MessageBox.Show("Item found!!");
dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
}
else if (src.Position == 0 && dataGridView1.Rows[0].Cells[2].Value.ToString() != text)
{
MessageBox.Show("Item not found!!");
}
else
{
MessageBox.Show("Item found!!");
dataGridView1.CurrentCell = dataGridView1.Rows[src.Position].Cells[2];
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
从另一个表单调用findText方法时出现错误,但是从主窗体调用此方法不会导致这样的错误.
我找到正确的语法来完成以下操作时遇到了一些麻烦:
是否可以使用LINQ(Lambda Expression)到.GroupBy数据,而不是使用通常的.Sum()或.Count(),我希望结果数据是Int的列表.
我定义了自己的类:Filter_IDs.它的构造函数需要两个参数:
public int? type; // Represents the object_type column from my database
public List<int?> objects; // Represents the object_id column from my database
Run Code Online (Sandbox Code Playgroud)
我想将数据库中的数据加载到此对象中.以下LINQ查询应该生成Filter_ID列表:
以下LINQ查询应该生成Filter_ID列表:
List<Filter_IDs> filterids = ef.filterLine
.GroupBy(fl => fl.objectType)
.Select(fl => new Filter_IDs { type = fl.Key, objects = fl.Select(x => x.object_id).ToList() })
.ToList();
Run Code Online (Sandbox Code Playgroud)
使用此查询不会产生构建错误,但会在RunTime上显示"NotSupportedException".
数据库看起来像这样可以让您更好地理解数据:
http://d.pr/i/mnhq+(droplr image)
提前谢谢,Gerben
我试图为我的侄子棋盘游戏制作属性特征随机数,我试图将属性写入外部文件,以便以后可以使用它们.当我试图写入文件时,它会出现错误
speedE = str('Speed -', str(speed))
TypeError: decoding str is not supported
Run Code Online (Sandbox Code Playgroud)
我的代码是将计算出的属性添加到属性的名称中.IE('Strength - ',strengthE)我的代码是......
import random
char1 = open('Character1.txt', 'w')
strength = 10
strength += int(random.randint(1, 12) / random.randint(1,4))
speed = 10
speed += int(random.randint(1, 12) / random.randint(1,4))
speedE = str('Speed -', str(speed))
char1.write(speedE)
strengthE = str('Strength -', str(strength))
char1.write(strengthE)
print(char1)
char1.close()
char2 = open('Character2.txt', 'w')
strength2 = 10
strength2 += int(random.randint(1, 12) / random.randint(1,4))
speed2 = 10
speed += int(random.randint(1, 12) / random.randint(1,4))
speedE2 = str('Speed -', str(speed)) …
Run Code Online (Sandbox Code Playgroud) 我有一个以前在NHibernate LINQ 2.1.2中工作的查询,但它在NH3中抛出NotSupportedException:
IQueryable<Tree> query = from flower in GetSession().Query<Flower>()
from leaf in flower.Stem.Leaves // <--- the problem is here with three jumps
where leaf.Color == Green
select flower;
Run Code Online (Sandbox Code Playgroud)
关系如下:
从NHibernate.Linq.Visitors.QueryModelVisitor中的第204行抛出异常.这是源代码中的方法:
public override void VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index)
{
if (fromClause is LeftJoinClause)
{
// It's a left join
_hqlTree.AddFromClause(_hqlTree.TreeBuilder.LeftJoin(
HqlGeneratorExpressionTreeVisitor.Visit(fromClause.FromExpression, VisitorParameters).AsExpression(),
_hqlTree.TreeBuilder.Alias(fromClause.ItemName)));
}
else if (fromClause.FromExpression is MemberExpression)
{
var member = (MemberExpression) fromClause.FromExpression;
if (member.Expression is QuerySourceReferenceExpression)
{
// It's a join …
Run Code Online (Sandbox Code Playgroud)