Tag: 线程exception

线程忽略KeyboardInterruptexception

我正在运行这个简单的代码: import threading, time class reqthread ( threading.Thread ): def __init__ (self): threading.Thread.__init__(self) def run ( self ): for i in range(0,10): time.sleep(1) print '.' try: thread=reqthread() thread.start() except (KeyboardInterrupt, SystemExit): print '\n! Received keyboard interrupt, quitting threads.\n' 但是当我运行它,打印 $ python prova.py ` . . ^C. . . . . . . . Exception KeyboardInterrupt […]

可以从System.ArgumentException派生吗?

如果我有一个方法来检查其参数的有效性,是否可以抛出我自己从System.ArgumentException派生的自定义exception? 我在问,因为ArgumentException本身是从System.SystemException派生的,我看到了一个冲突的指导方针,应用程序是否应该从SystemException派生。 (尽pipe间接地,从ArgumentException派生仍然等同于从SystemException派生。) 我看到很多指导说不从ApplicationException派生,而是从Exception派生。 我很高兴。 我不确定是否也可以从SystemException派生。 如果我不应该从SystemException派生,那么我应该从哪个派生我的"invalid argument"exception类?

exception处理是否需要面向对象的编程?

在我的编程经验的这一点上,我意识到我是如何被宠坏的,现在大多数语言(C ++,.Net,Java等)都可以使用exception处理,至less与C相比,我正在准备采取先进的C课程,让我真正思考这些术语与我目前的范式相比。 在C语言中,程序员应该首先防止错误发生,这对任何习惯于exception处理的人来说都是相当艰巨的。 对我来说,我遇到的任何有exception处理的语言都是面向对象的。 至less就我所知,第一个面向exception处理的面向对象语言是C ++,它是C的进化(如果我错了,请纠正我) 那么, 有没有关于一种允许exception处理的语言的面向对象本质的东西,还是作为一个function添加了exception处理,因为面向对象的语言真的开始变得很平常了? 什么是C缺乏说,C ++,在机器代码,使excation工作? 我发现这篇文章是关于exception处理如何在引擎下工作的,但不知道这些信息如何适用于我的问题( 即C是否缺less通知,延续等? )。 提前致谢。

在什么情况下C ++析构函数不会被调用?

我知道我的析构函数是在堆栈的正常展开和引发exception时调用的,而不是在调用exit()时调用的。 有没有其他的情况下,我的析构函数不会被调用? 信号如SIGINT或SIGSEGV怎么样? 我认为对于SIGSEGV来说,它们不会被调用,但是对于SIGNINT来说,我怎样才能知道哪些信号会将栈放开呢? 有没有其他的情况下,他们不会被叫?

Source = null的ImageSourceConverter错误

我将图像的Source属性绑定到一个string。 这个string可能是null,在这种情况下,我只是不想显示一个图像。 但是,我在我的debugging输出中得到以下内容: System.Windows.Data错误:23:无法将types'<null>'中的'<null>'转换为具有默认转换的'en-AU'文化types'System.Windows.Media.ImageSource'; 考虑使用Binding的Converter属性。 NotSupportedException:'System.NotSupportedException:ImageSourceConverter不能从(null)转换。 System.ComponentModel.TypeConverter.GetConvertFromException(Object value)at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o,Type destinationType,DependencyObject)上System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext上下文,CultureInfo文化,对象值) targetElement,CultureInfo culture,布尔isForward)' 我宁愿如果这不显示,因为它只是噪音 – 有没有办法压制它?

ObjectContext实例已经处理完毕,不能再用于需要连接的操作了

我有这样的看法: @model MatchGaming.Models.ProfileQuery @{ ViewBag.Title = "Index"; } <h2>Index</h2> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @using (Html.BeginForm("Results", "Profiles")) { @Html.ValidationSummary(true) <fieldset> <legend>ProfileQuery</legend> @Html.EditorFor(model=>model.SearchString) <p> <input type="submit" value="Create" /> </p> </fieldset> } <div> @Html.ActionLink("Back to List", "Index") </div> 我有这个控制器的HttpPost: [HttpPost] public ActionResult Results(ProfileQuery profileQuery) { Debug.Write(profileQuery.SearchString); using(var db = new MatchGamingEntities()) { var SearchUserName = db.Users.SingleOrDefault(a=> […]

Python:单行testing语句

有没有办法在python中尝试/除了成一条线? 就像是… b = 'some variable' a = c | b #try statement goes here 其中b是一个声明的variables, c不是…所以c会抛出一个错误, a会变成b …

Laravel捕获TokenMismatchException

TokenMismatchException可以使用try catch块捕获吗? 而不是显示debugging页面,显示“TokenMismatchException VerifyCsrfToken.php行46 …”,我希望它显示实际的页面,只是显示一个错误信息。 我没有与CSRF的问题,我只是希望它仍然显示页面,而不是debugging页面。 复制(使用Firefox):步骤: 打开页面( http://example.com/login ) 清除Cookies(域,path,会话)。 我在这里使用web开发工具栏插件。 提交表格。 实际结果:“哎呀,看起来像是出了问题”页面显示。 预期结果:仍然显示login页面,然后传递“令牌不匹配”的错误或其他东西。 请注意,当我清除cookie时,我没有刷新页面,令令牌生成一个新的密钥,并强制错误。 更新(新增表格): <form class="form-horizontal" action="<?php echo route($formActionStoreUrl); ?>" method="post"> <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>" /> <div class="form-group"> <label for="txtCode" class="col-sm-1 control-label">Code</label> <div class="col-sm-11"> <input type="text" name="txtCode" id="txtCode" class="form-control" placeholder="Code" /> </div> </div> <div class="form-group"> <label for="txtDesc" class="col-sm-1 control-label">Description</label> […]

如何知道哪个variables是try块中的罪魁祸首?

在某个try块中,我有两个Stringvariables,当我用户Integer.parseInt(string1)和Integer.parseInt(string2)时,可能会导致NumberFormatException 。 问题是,如果我发现一个例外,怎么知道哪个string是麻烦制造者? 我需要得到麻烦制造者的variables名称。 以下是一些示例代码: public class test { public static void main(String[] args) { try { String string1 = "fdsa"; String string2 = "fbbbb"; Integer.parseInt(string1); Integer.parseInt(string2); } catch (NumberFormatException e) { e.printStackTrace(); } } } 而e.printStackTrace()方法不会告诉我variables的名字; 它只是告诉我这个麻烦制造者的内容。 java.lang.NumberFormatException:对于inputstring:java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)处的“fdsa”位于java.lang.Integer处的java.lang.Integer.parseInt(Integer.java:580)。在sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在sun.reflect处的test.main(test.java:9)处的parseInt(Integer.java:615) .DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)java.lang.reflect.Method.invoke(Method.java:498) 进程使用退出码0结束 我需要知道variables名称的原因是我需要提示用户发生了什么事情。 例如,通过使用告诉用户string1是错误的 System.out.println(troubleMakerName + "is wrong!") 在我的要求中,用户应该input fd=(fileName,maxLength,minLength) 那么我将分析input的string并创build一些响应。 所以我想检查maxLength和minLength是否会抛出NumberFormatException 。 在这种情况下,如果minLength有问题,那么我需要提示用户minLength是错误的。

比多个catch块更优雅的exception处理?

使用C#,有没有更好的方式来处理多种types的exception,而不是一堆丑陋的catch块? 什么被认为是这种情况下的最佳做法? 例如: try { // Many types of exceptions can be thrown } catch (CustomException ce) { … } catch (AnotherCustomException ace) { … } catch (Exception ex) { … }