草庐IT

业务异常

全部标签

C# 我应该引发什么样的异常?

我目前正在trycatch中查找属性是否已正确设置为应该像这样的bool值...publicvoidRunBusinessRule(MyCustomTypecustomType){try{if(customType.CustomBoolProperty==true){DoSomething();}else{thrownewException("Thisisobviouslyfalseorpossiblynullletsthrowupanerror.");}}catch(Exception){throw;}}现在对我抛出这个错误的处理是我正在使用微软的源代码分析,它给了我一个错误,指出“

c# - 在 c# om nom nom 中吃异常

鉴于吃掉异常总是糟糕的juju并且重新抛出异常会丢失调用堆栈,重构以下内容的正确方法是什么?饮食异常(exception):try{…dosomethingmeaningful}catch(SomeExceptionex){//eatexception} 最佳答案 try{...}catch(SomeExceptione){//Dowhateverisneededwithethrow;//Thisrethrowsandpreservescallstack.} 关于c#-在c#omnomn

c# - 抛出异常后继续循环迭代

假设我有这样的代码:try{for(inti=0;i现在,很明显执行将在i==2停止,但我想让它完成整个迭代,以便在errorLog中有两个条目(对于i==2和i==4)那么,是否可以在抛出异常的情况下继续迭代? 最佳答案 只需将catch的范围更改为在循环内,而不是在循环外:for(inti=0;i 关于c#-抛出异常后继续循环迭代,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions

c# - 如何让异常在 C# 中定义自己的消息?

我想定义一个具有两个特殊属性的自定义异常:Field和FieldValue,并且我希望根据异常构造函数中的这两个值构建消息。不幸的是,消息是只读的。这就是我所拥有的,但它仍然需要传递消息。publicclassFieldFormatException:FormatException{privateFields_field;privatestring_fieldValue;publicFieldsField{get{return_field;}}publicstringFieldValue{get{return_value;}}publicFieldFormatException():b

C# - 解析异常失败?

我正在用C#编写程序,我想捕获将""(null)转换为int引起的异常。异常的名称是什么?编辑:我不确定我能否展示完整的代码...但我确定您不需要完整的代码,所以:intnum1=Int32.Parse(number1.Text);intnum2=Int32.Parse(number2.Text); 最佳答案 如果可以避免,请不要按异常编码!您要查找的异常名称称为FormatException。但是,首先对您尝试解析的对象执行TryParse会更明智,例如intvalue;if(!int.TryParse("1",outvalue)

visual-studio - VS 2012/2013 访问冲突异常

当我运行项目(F5)时,我在IDE中收到以下异常:Anunhandledexceptionoftype'System.AccessViolationException'occurredinSystem.Windows.Forms.dllAdditionalinformation:Attemptedtoreadorwriteprotectedmemory.Thisisoftenanindicationthatothermemoryiscorrupt.堆栈跟踪报告atSystem.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef

c# - 遍历 NHibernate 实体的 IQueryable 时出现消息 "plan b"的 Antlr 异常

我在尝试实现IQueryable时遇到了一个很奇怪的异常我有表格NHibernate.Linq.Antlr.Runtime.Tree.RewriteEmptyStreamException类型的异常只是说明planb,仅此而已。可以在http://pastebin.com/kR2dvDHd找到详细的异常情况下面是抛出异常的代码:varmatterExtractor=newMatterExtractor();varInactiveMatters=matterExtractor.GetMattersAtStatus(General.InactiveMatterStatus);Assert.

c# - ado.net transaction.commit 抛出信号量异常

当我提交交易时,我得到:System.Threading.SemaphoreFullException:Addingthespecifiedcounttothesemaphorewouldcauseittoexceeditsmaximumcount.atSystem.Threading.Semaphore.Release(Int32releaseCount)atSystem.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternalobj)atSystem.Data.ProviderBase.DbConnec

c# - AutoMapper.dll中出现 'AutoMapper.AutoMapperMappingException'类型的异常,但用户代码中没有处理

不知何故,我的代码不再起作用(它以前使用完全相同的代码确实起作用)。这是问题所在:代码我正在尝试使用以下代码将一些对象映射到ViewModel:配置:Mapper.CreateMap().ForMember(x=>x.Title,opt=>opt.MapFrom(src=>src.Book.Title)).ForMember(x=>x.Authors,opt=>opt.MapFrom(src=>src.Book.Authors.Select(x=>x.Name).Aggregate((i,j)=>i+","+j))).ForMember(x=>x.Identifiers,opt=>op

c# - 由于 DataGridViewImageColumn,DataGridView 在默认错误对话框中抛出异常

我提出这个问题是因为在网上找到答案花了太长时间,这可能是一个常见问题-这是我第二次在我的应用程序中遇到它。当带有DataGridViewImageCell的新行变得可见,并且没有设置默认值时,我的DataGridView会抛出以下异常:TheFollowingExceptionoccurredintheDataGridView:System.ArgumentException:Parameterisnotvalid.atSystem.Drawing.Image.FromStream(Streamstream,BooleanuseEmbeddedColorManagement,Boole