我已经处理了一些实例,我会抛出/重新抛出异常,知道它周围的代码会捕获特定的异常.但是,有没有时间你想要抛出异常,知道它不会被抓住?
或者至少,没有捕获异常?
除非处理权利,否则例外会立即停止申请?所以我想我问你是否想故意让你的应用程序死掉?
c# exception-handling exception try-catch unhandled-exception
我有一些通过cron运行的python脚本,当使用绝对路径调用脚本时,它们不再正确退出.它们将一直挂起,直到该过程终止.我相信它发生在我将/ var和/ home移动到另一个分区之后.
我检查了环境变量并且看不到任何明显错误,这在使用cron或bash子shell运行时发生,但在直接运行时不会发生.
如果我把它作为子shell运行它会挂起,直到我杀了它(ctrl-c),然后给我输出.
[wotstats@rock test]$ echo 'assert 0==1, "fails"' > test.py
[wotstats@rock test]$ /bin/bash -c "/usr/bin/python /var/home/wotstats/test/test.py"
^CTraceback (most recent call last):
File "/var/home/wotstats/test/test.py", line 1, in <module>
assert 0==1, "fails"
AssertionError: fails
Run Code Online (Sandbox Code Playgroud)
如果我不调用脚本,它会按预期终止而不会挂起:
[wotstats@rock test]$ /bin/bash -c "echo 'assert 0==1, \"fails\"' | /usr/bin/python"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: fails
Run Code Online (Sandbox Code Playgroud)
发生异常时,我会立即收到日志错误:
Dec 9 13:33:44 rock abrt: detected unhandled Python exception in '/var/home/wotstats/test/test.py'
Run Code Online (Sandbox Code Playgroud)
我根据输入运行了一些测试,发现即使调用/test.py和以root身份运行时也会出现此问题.我也尝试/ root和/ usr具有相同的效果.
这里询问了类似或相同的问题,并通过重新启动解决; 如果可以的话,我宁愿弄明白并避免重启.
在过去的几个小时里,我一直试图通过检查我的调用堆栈来解决这个问题,但仍然没有弄清楚发生了什么!
我的序列数据库基本上从文件中收集所需的信息,然后调用我的链接列表类以使用收集的信息创建一个新节点,并将该节点放在链接列表的末尾:
标题:
#ifndef SEQUENCE_H
#define SEQUENCE_H
#include "DNA.h"
#include "DNAList.h"
class SequenceDatabase
{
public:
//Default Constructors
SequenceDatabase();
//Methods
void importEntries(string);
private:
DNAList list;
};
#endif
Run Code Online (Sandbox Code Playgroud)
来源:
#include "SequenceDatabase.h"
#include "DNA.h"
#include "DNAList.h"
#include <fstream>
using namespace std;
SequenceDatabase::SequenceDatabase() //Default Constructor.
{
DNA object;
DNAList list;
}
void SequenceDatabase::importEntries(string name)
{
DNA* item;
ifstream file;
file.open(name);
if(!file.is_open())
{
cout << "Error opening file!" << endl;
exit(1);
}
char letter;
string label, sequence;
int ID, length, index;
file >> letter;
if(letter …Run Code Online (Sandbox Code Playgroud) import 'dart:async';
void main() {
divide(1, 0).then((result) => print('1 / 0 = $result'))
.catchError((error) => print('Error occured during division: $error'));
}
Future<double> divide(int a, b) {
if (b == 0) {
throw new Exception('Division by zero');
}
return new Future.value(a/b);
}
Run Code Online (Sandbox Code Playgroud)
目前我正在学习如何在 Dart 中使用 future,并且我陷入了这样一个简单的例子中。当用户尝试执行除以零时,我的未来会抛出异常。但是, .catchError 不处理我的异常。我得到了未处理的异常,并带有堆栈跟踪。我很确定我错过了一些明显的东西,但无法理解到底是什么。
据我了解,还有另一种方法来处理错误:
divide(1, 0).then((result) => print('1 / 0 = $result'),
onError: (error) => print('Error occured during division: $error'));
Run Code Online (Sandbox Code Playgroud)
使用命名可选参数 - onError。这样做仍然会导致未处理的异常。
我还想澄清一件事。我对吗?- 这两种方法之间的唯一区别是 .catchError() 还处理内部 future 抛出的错误(在外部 future 的 then() 方法内部调用的 future),而 onError …
我想要它,所以当我点击我的按钮时,我退出我的应用程序.我尝试了一个简单的for循环:
Private Sub CloseAllToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseAllToolStripMenuItem.Click
For Each Form In My.Application.OpenForms
Form.Close()
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
但是在使用此按钮关闭表单之外的所有表单之后,我收到此错误:
mscorlib.dll中发生了未处理的"System.InvalidOperationException"类型异常附加信息:集合已被修改; 枚举操作可能无法执行.
我相信这是因为我在循环之前关闭执行代码的表单可以转到下一个表单.如果是这种情况,我怎么能做到这一点,一旦最后一个表格关闭,我的循环结束?我甚至可以这样做吗?
我为Windows 10桌面创建了uwp app(.Net native).我使用HockeyApp收集实时崩溃报告.堆栈跟踪不提供信息.这是一个长期存在的问题,并没有解决方案.我尝试了这个,但它不起作用.我得到以下例外:
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
Arg_NullReferenceException
Microsoft.HockeyApp.Extensibility.Windows.UnhandledExceptionTelemetryModule.CoreApplication_UnhandledErrorDetected
The parameter is incorrect. The parameter is incorrect.
Run Code Online (Sandbox Code Playgroud)
在我的计算机上,应用程序运行稳定.也许这是由于Windows的版本.我认为这是由于我的xaml.对我来说纠正这些错误非常重要.但我不能拒绝这张桌子.任何想法如何找到这些错误的来源?
我是一个lisp noob尝试使用sbcl v1.0.50学习lisp.
我正在编写一个简单的记录器并遇到一个我不理解的内存故障,但这似乎与我编译脚本的方式有关.我把它归结为以下内容:
=== logger.lisp ===
(defparameter *log-stream* (open "/tmp/global-log"
:direction :output
:if-does-not-exist :create
:if-exists :append))
Run Code Online (Sandbox Code Playgroud)
=== main.lisp ===
(load "logger.lisp")
(defun main ()
(format *log-stream* "Hello world~%"))
Run Code Online (Sandbox Code Playgroud)
== == compile.lisp
#! /usr/bin/sbcl --script
(load "main.lisp")
(save-lisp-and-die "program" :toplevel #'main :executable t)
Run Code Online (Sandbox Code Playgroud)
当我编译并运行程序时,它会崩溃:
> ./compile.lisp
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into foo:
writing 6352 bytes from the read-only space at 0x20000000
writing 4064 bytes from the static space at 0x20100000
writing 43057152 …Run Code Online (Sandbox Code Playgroud) 尝试编写.ply解析器以在OpenGL中使用.ply模型.
试图开始阅读.ply文件并写出它的所有行.我的程序执行此操作但是当它打印出最后一行时,我得到Unhandled exception:
PLY parser.exe中0x62aad540(msvcr100d.dll)的未处理异常:0xC0000005:访问冲突读取位置0x00000000.
这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
using namespace std;
int main ()
{
char buffer[10000];
FILE * myFile;
myFile = fopen("walkman.ply", "r");
if(myFile != NULL)
{
while (!feof(myFile))
{
cout<<fgets(buffer, 10000, myFile);
}
fclose(myFile);
}
else
{
cout<<"file not found"<<endl;
}
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这可能是我的代码中的愚蠢错误,但如果有人能够发现导致此错误的错误,那将会很棒.
我使用以下MSVC++控制台应用程序代码(在Windows 8.1,Release,Win32上运行)尝试将顶级异常返回给我:
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS exception)
{
printf("Got an unhandled exception.");
return EXCEPTION_CONTINUE_SEARCH;
}
int _tmain(int argc, _TCHAR* argv[])
{
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
int a = 0;
int b = 0;
int c = a / b;
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我UnhandledExceptionFilter实际上似乎并没有被调用此示例中抛出的除零异常,否则我会期望显示"得到未处理的异常"日志消息.这是为什么?
我们有一个.NET 3.5程序集(dll)由VB6"代理"(exe)通过COM接口执行.VB6代码确实调用:
' Ensure that no system dialog comes up when we GPF.
PreviousErrorMode = SetErrorMode(SEM_NOGPFAULTERRORBOX)
SetErrorMode PreviousErrorMode Or SEM_NOGPFAULTERRORBOX
' Assign our Exception Handler for this process.
PreviousExceptionFilter = SetUnhandledExceptionFilter(AddressOf UnhandledExceptionFilter)
Run Code Online (Sandbox Code Playgroud)
VB6 UnhandledExceptionFilter将异常转换为VB6引发的错误.(但是这里也没有被调用,这个VB6代码多年来没有被改变 - 甚至没有被重新编译过.)
在由VB6代码创建的第一个.NET对象的构造函数中,我添加了一个处理程序AppDomain.CurrentDomain.UnhandledException(并且,为了调试此问题,我添加了一个for Windows.Forms.Application.ThreadException,但它没有帮助,不是我们有任何无论如何,由.NET显示的UI).
我确信UnhandledException在VS2008中开发此代码时事件已经抓住了,但我不确定我是否已在VS2015中看到过它.
代码运行多个线程,其中一些执行主要目的,包括插入和更新SQL Server数据,以及通过TCP协议进行通信,TCP协议由其他线程处理,包括a BackgroundWorker.
执行主要目的的人是:
taskThread = New Thread(AddressOf EnsureTaskCompletes)
taskThread.SetApartmentState(Threading.ApartmentState.STA)
taskThread.Start()
Run Code Online (Sandbox Code Playgroud)
向你展示更多的代码是太专有和复杂了,但我在调试这个问题的同时调整了代码,而Throw New Exception不是最终具有相同效果的复杂代码.(*)
这个"简单"的异常没有被处理过,UnhandledExceptionHandler并且只是默默地终止了程序,除了我打开了非托管调试.
AppDomain.CurrentDomain.UnhandledException当.NET Framework"仅"作为dll加载时,是否存在记录的更改行为?
(因为COM重新注册的,我不想打造VS2008以前的版本尚未确认有是一个行为改变.我已经确认了.NET 3.5 的Exe由创建一个VS2015编译Thread抛出未处理的异常并处理 …