标签: unhandled-exception

Node.js 中管道中未处理的流错误

我在 Node.js 和 Express 中使用本地代理,代码如下:

app.post('/', function(req, res){
  var newurl =  req.body.url;
  var options = {
    url: newurl,
    headers: {
     'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
     'Accept-Language':'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
     'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
    }
  };
  res.writeHead(200, {
    'Content-Type': 'text/html',
    'Access-Control-Allow-Origin' : '*'});
  try {
    request(options).pipe(res);
  } catch (err) {
    res.write(err.message);
    res.end();
  }
});
Run Code Online (Sandbox Code Playgroud)

它适用于大多数网站,但当我尝试从某些网站检索页面时,Node 会抛出以下错误:

stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^

Error: socket hang up
    at createHangUpError (_http_client.js:200:15)
    at Socket.socketOnEnd (_http_client.js:285:23)
    at emitNone (events.js:72:20)
    at Socket.emit …
Run Code Online (Sandbox Code Playgroud)

error-handling unhandled-exception node.js

5
推荐指数
1
解决办法
1万
查看次数

.Net Framework:当未捕获异常时,不会调用Finally块

一个简单的控制台应用程序,在 Visual Studio 2019、.Net Framework 4.7、Windows 中:

static void Main(string[] args)
{
    try
    {
         Console.WriteLine("In try");
         throw new IndexOutOfRangeException();
    }
    finally
    {        *// Surprisingly this part is not being executed.*
         Console.WriteLine("In finally");
         Console.ReadLine();
    }                       
}
Run Code Online (Sandbox Code Playgroud)

我确信在没有异常的情况下以及在有异常的情况下都会调用finally块。我在文档中读到:

但是,如果异常未处理,则finally块的执行取决于异常展开操作的触发方式。反过来,这取决于您的计算机的设置方式。

关联

嗯,我很困惑。我是否需要对这个“展开操作”做一些事情,以便在出现未处理的异常时调用finally?

c# finally try-catch console-application unhandled-exception

5
推荐指数
0
解决办法
248
查看次数

.NET 3.5 Compact Framework能否具有全局错误处理程序?

有没有办法为.NET CF 3.5应用程序中所有其他未处理的异常编写错误处理程序?我没有OnError在紧凑Application类上看到任何类型的事件(或任何事件).

仅在谷歌搜索似乎提出了对ASP.NET中全局错误处理的引用,这对我没有帮助,因为这是一个胖客户端手持应用程序.

error-handling compact-framework exception-handling global unhandled-exception

4
推荐指数
1
解决办法
1889
查看次数

如何在从.so调用函数抛出异常时避免崩溃

这是我做的,我想优雅地处理这个异常:

code_snippet:my.cpp

#include<iostream>
extern "C" void some_func()
{
    throw "(Exception Thrown by some_func!!)";
}
Run Code Online (Sandbox Code Playgroud)

code_snippet:exception.c

#include <stdio.h>
extern void some_func();
int so_main()
{
    some_func();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

从上面的两个片段我使用以下命令创建了一个shared_object libexception.so:

g++ -c -fPIC src/my.cpp
gcc -c -ansi -fPIC src/exception.c
g++ -fPIC -shared -o libexception.so
Run Code Online (Sandbox Code Playgroud)

然后我从main.cpp code_snippet:main.cpp中调用了函数so_main

#include<iostream>
#include <dlfcn.h>
using namespace std;
extern "C" void some_func();
int main()
{
    int (*fptr)() = 0;
    void *lib = dlopen("./libexception.so", RTLD_LAZY);
    if (lib) {
        *(void **)(&fptr) = dlsym(lib, "so_main");
        try{
           if(fptr) (*fptr)();    <-- problem …
Run Code Online (Sandbox Code Playgroud)

c c++ exception-handling unhandled-exception

4
推荐指数
1
解决办法
940
查看次数

'CrystalDecisions.Shared.SharedUtils'的类型初始值设定项引发了异常

我正在研究一个项目并遇到了一个问题.当我运行我的代码时,我收到此错误消息:

The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception
Run Code Online (Sandbox Code Playgroud)

消息的标题是"TypeInitializerException未处理".

我在这行代码中收到此错误:

this.crystalReportViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
Run Code Online (Sandbox Code Playgroud)

我一直在寻找解决这个问题的方法,但我一直在遇到另一个问题.我发现的关于如何解决这个问题的一切都说平台目标应该改为x86.遵循该建议的所有评论总是积极的,因为它似乎适用于每个人,但它不适合我.我还尝试将平台目标作为x64.当我这样做时,我没有收到先前声明的错误,但我收到的新错误如下:

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Run Code Online (Sandbox Code Playgroud)

消息的标题是"InvalidOperationException未处理".错误就在这条线上:

db.Open();
Run Code Online (Sandbox Code Playgroud)

db,当然,被设置为新的OleDbConnection(连接).connection =一个Access数据库.

当平台目标是x86时,为什么我收到第一个错误而不是第二个错误,如果平台目标是x64,反之亦然?

堆栈跟踪:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'CrystalDecisions.Shared.SharedUtils' threw an exception.
  Source=CrystalDecisions.Shared
  TypeName=CrystalDecisions.Shared.SharedUtils
  StackTrace:
       at CrystalDecisions.Shared.SharedUtils.get_CurrentControl()
       at CrystalDecisions.Shared.SharedUtils.GetEffectiveCulture()
       at CrystalDecisions.Shared.LocaleManager..ctor()
       at CrystalDecisions.Windows.Forms.CrystalReportViewer.InitReportViewer()
       at CrystalDecisions.Windows.Forms.CrystalReportViewer..ctor()
       at Client_Manager.ReportViewer.InitializeComponent() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.Designer.cs:line 31
       at Client_Manager.ReportViewer..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\ReportViewer.cs:line 27
       at Client_Manager.Form1..ctor() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Form1.cs:line 174
       at Client_Manager.Program.Main() in C:\Users\Will\Desktop\Client_Manager\SyndicateII\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2010 unhandled-exception crystal-reports-xi

4
推荐指数
2
解决办法
5万
查看次数

JAVA中未处理的异常类型

我在JAVA的同一个包中有两个类.

我有一个构造函数的一个类,我尝试创建自己:

public class ZooException extends Exception {

        public ZooException(String error) {
            super(error);
        }   
}
Run Code Online (Sandbox Code Playgroud)

另一个类需要在某一点调用此异常:

public class Zoo<T extends Animal>

Zoo(int capacity) {
        if (capacity <= 1) {
        throw new ZooException("Zoo capacity must be larger than zero");
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里注意到两件事

  1. 在ZooException类中,我收到一个警告:"可序列化类CageException不声明类型为long的静态最终serialVersionUID字段"
  2. 在Zoo类中,以"throw new"开头的行,我得到一个编译错误:"未处理的异常类型CageException"

关于我可以做什么来解决Zoo类中的这个错误的想法?先感谢您!

java exception-handling exception unhandled-exception

4
推荐指数
1
解决办法
2万
查看次数

在 Windows 服务中处理 AppDomain.CurrentDomain.UnhandledException

我有充当同步软件的窗口服务。我想在我的服务上添加无人处理的异常日志记录,所以我program.cs像这样修改了我的:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
    static void Main()
    {
        // Register Unhandled Exception Handler
        AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(UnhandledExceptionHandler);

        // Run Service
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new Service() 
        };
        ServiceBase.Run(ServicesToRun);
    }

    static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
    {
        // Get Exception
        Exception ex = (Exception)args.ExceptionObject;

        // Generate Error
        string ErrorMessage = String.Format(
            "Error: {0}\r\n" +
            "Runtime Terminating: {1}\r\n----- ----- ----- …
Run Code Online (Sandbox Code Playgroud)

c# exception unhandled-exception

4
推荐指数
1
解决办法
5726
查看次数

在 JUnit 中,当 @Test 方法抛出未处理的异常时,@After 方法会运行吗?

即使@Test 方法抛出未处理的异常或者这实际上是由 JUnit 内部完成的,我将如何确保我的 @After 方法运行?

java junit unhandled-exception

4
推荐指数
1
解决办法
1597
查看次数

未处理的异常在被捕后仍然会崩溃应用程序

我有一个WPF应用程序,它包含多个具有表单,类,基类等的项目.

由于代码库很大,我想确保如果发生异常,我可以捕获它,通知用户并让应用程序继续运行而不会崩溃.我理解这样做的利弊.

在我的应用程序的App.xaml.cs中:

private void OnApplicationStartup(object sender, StartupEventArgs e)
{
    Application.Current.DispatcherUnhandledException += CurrentOnDispatcherUnhandledException;
    AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
    Dispatcher.UnhandledException += DispatcherOnUnhandledException;
    UI.Views.Windows.MainWindow.Show();
}

private void DispatcherOnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs dispatcherUnhandledExceptionEventArgs)
{
    MessageBox.Show("TEST 3");
}

private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
    MessageBox.Show("TEST 2");
}

private void CurrentOnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs dispatcherUnhandledExceptionEventArgs)
{
    MessageBox.Show("TEST 1");
}
Run Code Online (Sandbox Code Playgroud)

如果在任何地方发生异常,那么显示的消息框很棒,问题就在它显示应用程序仍然崩溃的消息之后.如果我在调试中运行应用程序,Visual Studio将跳转到发生异常的地方,如果我继续它将转到消息框.

我认为问题与此有关,但我不确定.有没有办法像上面那样捕获异常,但同时没有应用程序崩溃?

谢谢

编辑 进入UnhandledException部分的异常将是大多数公园的NullReference,NotSupported或Database Exceptions.如果像"Stack Overflow"这样的"严重"异常,我会简单地通知用户并杀死应用程序.我仍然需要找到一种方法来阻止应用程序崩溃非严重异常.

wpf exception-handling visual-studio-2010 unhandled-exception c#-4.0

3
推荐指数
1
解决办法
5520
查看次数

Apache Commons Lang:从2.3升级到3.3.1 - UnhandledException怎么样?

我最近将我的项目的Apache Commons版本(commons-lang)从版本2.3升级到版本3.3.1(最新的稳定版).

在我的代码中有使用特定的异常,如UnhandledException,我只是想知道如果我使用最新版本,哪个是替换此类异常,因为我使用了大量错误.

版本3中定义了其他异常,但与此类似.

java replace unhandled-exception apache-commons-lang

3
推荐指数
1
解决办法
683
查看次数