来自版本7的Node.js具有async/await语法糖用于处理promises,现在在我的代码中经常出现以下警告:
(node:11057) UnhandledPromiseRejectionWarning: Unhandled promise
rejection (rejection id: 1): ReferenceError: Error: Can't set headers
after they are sent.
(node:11057) DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有提到缺少捕获的线.有没有办法找到它而不检查每个try/catch块?
为了学习Angular 2,我正在尝试他们的教程.
我收到这样的错误:
(node:4796) UnhandledPromiseRejectionWarning: Unhandled promise rejection (r ejection id: 1): Error: spawn cmd ENOENT
[1] (node:4796) DeprecationWarning: Unhandled promise rejections are deprecated.
In the future, promise rejections that are not handled will terminate the Node.
js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)
我在SO中经历了不同的问题和答案,但无法找出"未处理的承诺拒绝"是什么.
任何人都可以简单地解释一下它是什么Error: spawn cmd ENOENT,也是什么,当它出现时,我必须检查以摆脱这个警告?
假设我有一个类和一个方法
class A {
void foo() throws Exception() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想为A一个流传递的每个实例调用foo,如:
void bar() throws Exception {
Stream<A> as = ...
as.forEach(a -> a.foo());
}
Run Code Online (Sandbox Code Playgroud)
问题:如何正确处理异常?代码无法在我的机器上编译,因为我没有处理foo()可能抛出的异常.在throws Exception的bar似乎是没用在这里.这是为什么?
为什么是UnhandledExceptionEventArgs.ExceptionObject一个对象而不是一个Exception?
我依附于AppDomain.UnhandledException.
我想UnhandledExceptionEventArgs.ExceptionObject加入Exception并插入它.
考虑到这一点,它会永远是空的吗?
在MSDN文档不exatly有用.
获取未处理的异常对象.
Visual Studio曾经有一个特定的复选框"Break on Un-handling exception".在2015年,这已被删除(或移动到我找不到的地方).因此,如果我未能提供用户级异常处理程序,那么现在我的转换项目不再中断.我不想打破所有"抛出异常",因为我处理特定的异常.就在我无法提供特定处理程序的地方.
现在我的代码只退出当前程序并继续在下一个调用堆栈位置执行,而不是好.
任何人都知道如何在Visual Studio 2015中获得此功能?我昨天刚升级到社区版.
c# exception-handling unhandled-exception visual-studio-2015
如何捕获ASP.NET Web Api中发生的所有未处理的异常,以便我可以记录它们?
到目前为止,我尝试过:
ExceptionHandlingAttributeApplication_Error方法Global.asax.csAppDomain.CurrentDomain.UnhandledExceptionTaskScheduler.UnobservedTaskException在ExceptionHandlingAttribute成功处理时引发的控制器操作方法和操作筛选范围内,但其他异常没有被处理,例如例外:
IQueryableaction方法返回的异常无法执行时抛出的异常HttpConfiguration.MessageHandlers)基本上,如果异常将导致500内部服务器错误返回到客户端,我希望它被记录.实现Application_Error在Web窗体和MVC中完成了这项工作 - 我可以在Web Api中使用什么?
class throwseg1
{
void show() throws Exception
{
throw new Exception("my.own.Exception");
}
void show2() throws Exception // Why throws is necessary here ?
{
show();
}
void show3() throws Exception // Why throws is necessary here ?
{
show2();
}
public static void main(String s[]) throws Exception // Why throws is necessary here ?
{
throwseg1 o1 = new throwseg1();
o1.show3();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么编译器报告方法show2(),show3()以及main()具有
未报告的异常必须捕获或声明要抛出的异常
当我throws Exception从这些方法中删除?
java exception-handling unhandled-exception throws checked-exceptions
到目前为止,我只是在程序Application.Run的Program.cs入口点周围放置一个try/catch块.这会在调试模式下很好地捕获所有异常,但是当我在没有调试模式的情况下运行程序时,不再处理异常.我得到了未处理的异常框.
我不希望这种情况发生.我希望在非调试模式下运行时捕获所有异常.该程序有多个线程,最好是来自它们的所有异常都被同一个处理程序捕获; 我想记录数据库中的异常.有没有人对如何做到这一点有任何建议?
我有一个小型的WinForms应用程序,它利用BackgroundWorker对象来执行长时间运行的操作.
后台操作会抛出偶然的异常,通常是当有人打开正在重新创建的文件时.
无论代码是否从IDE运行,.NET都会弹出一个错误对话框,通知用户发生了未处理的异常.使用Release配置编译代码也不会改变它.
根据MSDN:
如果操作引发了代码无法处理的异常,则BackgroundWorker会捕获异常并将其传递到RunWorkerCompleted事件处理程序,在该处理程序中,它作为System.ComponentModel .. ::.RunWorkerCompletedEventArgs的Error属性公开.如果您在Visual Studio调试器下运行,则调试器将在DoWork事件处理程序中引发未处理的异常的位置中断.
我希望有时抛出这些异常,并希望在RunWorkerCompleted事件而不是DoWork中处理它们.我的代码正常工作,并且在RunWorkerCompleted事件中正确处理错误,但我不能在我的生活中弄清楚如何停止.NET错误对话框抱怨发生"未处理的异常".
是不是BackgroundWorker应该自动捕获该错误?这不是MSDN文档中的内容吗?什么我需要做的通知.NET,这个错误是被处理,同时仍允许例外propage到RunWorkerCompletedEventArgs的错误属性?
protected override void OnStart(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Thread.Sleep(10000);
throw new Exception();
}
void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
我在我的Windows服务中将调试器附加到上面的代码,在CurrentDomain_UnhandledException中设置断点,但它从未被命中.弹出的异常是说它未处理,然后服务停止.我甚至尝试在事件处理程序中放入一些代码,以防它被优化掉.
这不是在Windows服务中设置未处理的异常处理的正确方法吗?
c# ×5
exception ×2
java ×2
.net ×1
angular ×1
async-await ×1
debugging ×1
es6-promise ×1
java-8 ×1
java-stream ×1
javascript ×1
node.js ×1
promise ×1
spawn ×1
throws ×1
warnings ×1
winforms ×1