类型未处理的异常? [英] An unhandled exception of type ?

查看:93
本文介绍了类型未处理的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的wpf应用程序中,我有一个按钮从某些设备获取数据。当我点击按钮时,我得到下一个异常。



PresentationFramework.dll中出现'JKKR.Core.Exceptions.EIncorrectDeviceId'类型的未处理异常



以下是我的代码的一部分:

Hi everybody again,
In my wpf application, i have a button to get data from some device. When i "click" the button, i get the next exception.

"An unhandled exception of type 'JKKR.Core.Exceptions.EIncorrectDeviceId' occurred in PresentationFramework.dll"

Here is a part of my code:

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button.Click
              

SpyModem.GetSatelliteMemory(Sate, "0256", 1, memory)
 TextBox1.Text = Sate

    End Sub





详细信息:我的应用程序由许多Windows组成(公式Y)。因此,在某些情况下,我必须通过单击按钮调用另一个窗口(处方集)。

当我点击按钮时,程序会显示问题所在的行:





Details: My application is composed by many Windows (formulary). So, In some cases, I must call another window (formulary) by clicking on a button.
When i Click the Button, the program show the line where is the problem:

    Public Sub Button_Acqui(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

       
        Dim fenetreAcqui As New Acquisition()
        fenetreAcqui.Fenetre_main = Me.Fenetre_main


           fenetreAcqui.ShowDialog()
End Sub



最后一个方法打开一个新窗口。该窗口位于ViewBox内。

问题出在下一行:


The last methode open a new window. That window is within of ViewBox.
The problem is in the next line:

fenetreAcqui.ShowDialog()





注意:我有一个DLL库。

有人可以给出一些关于这个问题的线索吗?是关于父和子的东西?



Note: I have a DLL Library.
Somebody can give some clue about this problem? is something about parent and child?

推荐答案

首先,在调试器下运行它,找出抛出异常的位置。在它发生之前放置断点并使用VSWatch窗口来检查变量。有关相关呼叫所需的参数和其他要求,请参阅设备文档。显示VS调用堆栈窗口(在调试菜单下)以找出堆栈和异常传播的路径。例如,您将从初始UI事件中看到从它的根本原因开始发生的所有事情。解决问题。



您需要捕获每个堆栈顶部堆栈帧的所有异常。不要抓太多,保持必要的最低限度,你真正知道如何处理异常。 UI具有一个特殊功能,可以捕获顶级偶数处理循环中的所有异常。对于WPF,这是通过 Application.DispatcherUnhandledException 事件完成的:

http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx [ ^ ]。



你应该总是这样做。如果出现问题,您可以选择为研究添加其他代码:当捕获到某些异常时,输出其堆栈跟踪:

http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx [ ^ ]。



这只是一个字符串,它将显示相同的异常传播路径,就像调试器下使用的调​​用堆栈一样。在极少数情况下,当调试器难以使用时,您只需记录异常信息(带有堆栈跟踪)并仍然可以解决问题。有关日志记录,请参阅:

http:// msdn。 microsoft.com/en-us/library/system.diagnostics.eventlog.aspx [ ^ ]。



-SA
First of all, run it under the debugger and find out where the exception was thrown. Put a breakpoint before it happens and use the VS "Watch" window to inspect variable. Consult the device documentation on the parameters required for the call in question and other requirements. Show VS "Call stack" windows (under the "Debug" menu) to find out the stack and the path of the propagation of the exception. You will see all what happens starting from the root cause of it, from the initial UI event, for example. Fix the problem.

You need to catch all exceptions on the top stack frame of each stack. Don't catch too much, keep it to necessary minimum, where you really know what to do with exception handling. UI has a special feature to catch all exception in the top even handling loop. For WPF, this is done via the Application.DispatcherUnhandledException event:
http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx[^].

You should always do that. In case of some problem, you can alternatively add additional code for the research: when some exception is caught, output its stack trace:
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx[^].

This is just a string, and it will show you the same exception propagation path, as with the "Call Stack" used under the debugger. In rare cases when debuggers is hard to use, you can simply log exception information (with stack trace) and still dig out the problem. For logging, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

—SA


这篇关于类型未处理的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆