全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2363
推到 Plurk!
推到 Facebook!

delphi 發生exception的等級

尚未結案
ivankuo
中階會員


發表:132
回覆:272
積分:95
註冊:2002-11-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-05 10:07:33 IP:61.221.xxx.xxx 未訂閱
小弟想要知道若程式發生exception,有分別哪種等級程式可以繼續,哪些最好強制關閉程式,如果用try.. except ..包起來的話,是否發生例外的時候都能保證能繼續執行程式而不受此例外影響??
------
ivankuo
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-10 18:23:17 IP:220.139.xxx.xxx 未訂閱
在 VCL 中有許多內建的 Exception 的物件,這些都是 VCL 系統在元件操作過程中可能發生的 Exception。 在實際的應用中,在寫程式時應該是以不發生 Exception 為原則下去寫作的,當然,有些可能為了避免某個或某幾個 Exception 可能要多做一些判斷而減低效能,為使正常操作能更快完成,所以寫一些可能會發生 Exception 的 code,如可能會發生除0,或指標指到 nil 的狀態,但發生機率極小,如果發生,可以強制略過或不以處理時,則例外都可以不處理,繼續 GO。 如果,程式的流程是不允許有錯的,而在寫作時,已避掉可能的 Exception,這樣如果執行時還是發生 Exception 則應準備關閉程式,至少要關閉此模組。 當然,如果您的程式夠強還能自動回復,那就只需在 Exception 的處理中,將狀態重置即可,這樣就不需要關閉程式或重開了。    其實,例外的處理都是 Case by Case 的,沒有一定的對或錯。 最重要的應該是客戶能不能接受。 因為程式是否還可以繼續執行,得由您自行判斷。    以下取自 BCB5 online help
引言:
C  Builder includes a large set of built-in exception classes for 
automatically handling divide-by-zero errors, file I/O errors, 
invalid typecasts, and many other exception conditions. All VCL 
exception classes descend from one root object called Exception. 
Exception encapsulates the fundamental properties and methods for 
all VCL-type exceptions and provides a consistent interface for 
applications to handle exceptions.     You can pass exceptions to a catch block that takes a parameter of 
type Exception. Use the following syntax to catch VCL exceptions:    catch (const exception_class &exception_variable)    You specify the exception class that you want to catch and provide a 
variable by which to refer to the exception.    Following is an example of how to throw a VCL exception:    void __fastcall TForm1::ThrowException(TObject *Sender)
{
  try
  {
    throw Exception("VCL component");
  }
  catch(const Exception &E)
  {
    ShowMessage(AnsiString(E.ClassName())  E.Message);
  }
}    The throw statement in the previous example creates an instance of 
the Exception class and calls its constructor. All exceptions 
descended from Exception have a message that can be displayed, 
passed through constructors, and retrieved through the Message 
property.
Selected VCL exception classes are described below. 

=================== ============================================================
EAbort              Stops a sequence of events without displaying an error
                    message dialog box.
EAccessViolation    Checks for invalid memory access errors.
EBitsError          Prevents invalid attempts to access a Boolean array.
EComponentError     Signals an invalid attempt to register or rename a component.
EConvertError       Indicates string or object conversion errors.
EDatabaseError      Specifies a database access error.
EDBEditError        Catches data incompatible with a specified mask.
EDivByZero          Catches integer divide-by-zero errors.
EExternalException  Signifies an unrecognized exception code.
EInOutError         Represents a file I/O error.
EIntOverflow        Specifies integer calculations whose results are too large for
                    the allocated register.
EInvalidCast        Checks for illegal typecasting.
EInvalidGraphic     Indicates an attempt to work with an unrecognized graphic file
                    format.
EInvalidOperation   Occurs when invalid operations are attempted on a component.
EInvalidPointer     Results from invalid pointer operations.
EMenuError          Involves a problem with menu item.
EOleCtrlError       Detects problems with linking to ActiveX controls.
EOleError           Specifies OLE automation errors.
EPrinterError       Signals a printing error.
EPropertyError      Occurs on unsuccessful attempts to set the value of a property.
ERangeError         Indicates an integer value that is too large for the declared
                    type to which it is assigned.
ERegistryException  Specifies registry errors.
EStackOverflow      Occurs when the stack grows into the final guard page.
EZeroDivide         Catches floating-point divide-by-zero errors.
=================== ============================================================    As you can see from the selected list above, the built-in VCL 
exception classes handle much of the exception handling for you and 
can simplify your code. There are other times when you will need to 
create your own exception classes to handle unique situations. You 
can declare a new exception class making it a descendant of type 
Exception creating as many constructors as you need (or copy the 
constructors from an existing class in SYSUTILS.HPP).
由所攔下來的 E.ClassName() 可以判斷是上述那個 VCL 的 Exception,或是您自定的 Exception,另外,也可以由 E.Message 來判斷。 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell.... 發表人 - dllee 於 2004/03/10 19:09:50 發表人 - dllee 於 2004/03/10 19:11:14
------
http://www.ViewMove.com
系統時間:2024-06-18 21:18:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!