delphi线程异常处理_Delphi异常处理中的异常处理

本文探讨了Delphi编程中异常处理的重要性,解释了如何使用try/except来处理异常,并指出处理异常时会自动销毁异常对象。此外,还讨论了未处理异常时Delphi如何显示错误对话框,以及如何通过TApplicationEvents.OnException事件创建更友好的用户错误提示。
摘要由CSDN通过智能技术生成

delphi线程异常处理

Here's an interesting fact: No code is error free — in fact, some code is full of "errors" on purpose.

这是一个有趣的事实:没有代码没有错误-实际上,某些代码故意充满了“错误”。

What's an error in an application? An error is an incorrectly coded solution to a problem. Such are logic errors that could lead to wrong function results where everything seems nicely put together but the result of the application is completely unusable. With logic errors, an application might or might not stop working.

应用程序中有什么错误? 错误是对问题的错误编码解决方案。 这些是逻辑错误 ,可能导致错误的功能结果,所有内容看似很好地组合在一起,但应用程序的结果完全无法使用。 遇到逻辑错误, 应用程序可能会或可能不会停止运行。

Exceptions can include errors in your code where you try to divide numbers with zero, or you try using freed memory blocks or try providing wrong parameters to a function. However, an exception in an application is not always an error.

异常可能包括代码中的错误,您尝试将数字除以零,或者尝试使用释放的内存块或向函数提供错误的参数。 但是,应用程序中的异常并不总是错误。

异常和异常类 ( Exceptions and the Exception Class )

Exceptions are special conditions that require special handling. When an error-type condition occurs the program raises an exception.

例外是需要特殊处理的特殊条件。 当发生错误类型的情况时,程序将引发异常。

You (as the application writer) will handle exceptions to make your application more error-prone and to respond to the exceptional condition.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TApplication.OnIdle   当应用程序变为空闲时,OnIdle事件发生。   使用OnIdle事件,可以写一个应用程序空闲时执行特定处理的事件处理程序。当应用程序不处理代码时,称为应用程序空闲。例如,当应用程序等待来自用户的输入时,应用程序为空闲。   TIdleEvent类型是OnIdle事件的类型,它指向一个应用程序空闲时运行的方法。TIdleEvent类型有一个布尔型参数Done,默认时该参数为True。若参数Done为True,当OnIdle事件返回时,调用Windows API WaitMessage函数。只有在应用程序消息队列出现一个新消息时,WaitMessage函数才放弃对其他应用程序的控制。参数Done为False时,即使应用程序不忙,也不放弃对其他应用程序的控制。   当应用程序转移到空闲状态时,只调用一次OnIdle事件。除非参数Done设置为False,否则不连续调用OnIdle事件。将参数Done设置为False的应用程序,将消耗过多的CPU时间,从而影响整个系统性能。 在delphi, 当在一个窗口上放置一个ApplicationEvents控件时,Application将会把所有的事件都转寄到ApplicationEvents; 也就是说,ApplicationEvents可以拦截到应用程序的全部事件,包括OnActivate\OnHelp\OnIdle\OnRestore\OnShortCut等等, 甚至可能通过OnMessage事件,在其截取所有post到应用程序所有窗口的消息,如WM_PAINT,WM_KEYDOWN, WM_KEYUP等常见的windows消息; 所以当有消息到来的时候就会触发它的OnMessage事件,在OnMessage监视消息就可以了。 Action的事件有OnExecute和OnUpdate,OnExecute事件在控制被触发时响应,比如说按钮被按下,菜单被按下,而OnUpdate事件是在应用程序空闲时被调用, APPLICATIONEVENTS是用来捕获程序级事件的 ApplicationEvents1Message(var Msg: tagMSG;var Handled: Boolean); {通过 Perform 向窗体发送 消息; OnMessage 收不到} {通过 SendMessage 向窗体发送 消息; OnMessage 收不到} {通过 PostMessage 向窗体发送  消息; OnMessage 可以收到}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值