Ada 程式設計/庫/Ada.Exceptions
外觀
此語言功能從 Ada 95 開始可用。
Ada.Exceptions 是自 Ada 95 以來 預定義語言環境 的一個單元。
包 Ada.Exceptions 允許您分析已捕獲的異常,以關聯訊息引發異常或儲存異常事件以供以後處理。
以下示例展示瞭如何實現一個“最後手段”錯誤處理程式,它只顯示與發生的錯誤相關的資訊。
withAda.Exceptions;procedureNumeric_6ispackageExeptrenamesAda.Exceptions; ...exceptionwhenAn_Exception :others=> T_IO.Put_Line (Exept.Exception_Information (An_Exception));endTry;
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual -- -------------------------------------------------------------------------withAda.Streams;packageAda.ExceptionsispragmaPreelaborate (Exceptions);typeException_Idisprivate;pragmaPreelaborable_Initialization (Exception_Id); Null_Id :constantException_Id;functionException_Name (Id :inException_Id)returnString;functionWide_Exception_Name (Id :inException_Id)returnWide_String;functionWide_Wide_Exception_Name (Id :inException_Id)returnWide_Wide_String;typeException_Occurrenceislimitedprivate;pragmaPreelaborable_Initialization (Exception_Occurrence);typeException_Occurrence_AccessisaccessallException_Occurrence; Null_Occurrence :constantException_Occurrence;procedureRaise_Exception (E :inException_Id; Message :inString := "");pragmaNo_Return (Raise_Exception);functionException_Message (X :inException_Occurrence)returnString;procedureReraise_Occurrence (X :inException_Occurrence);functionException_Identity (X :inException_Occurrence)returnException_Id;functionException_Name (X :inException_Occurrence)returnString; -- Same as Exception_Name(Exception_Identity(X)).functionWide_Exception_Name (X :inException_Occurrence)returnWide_String; -- Same as Wide_Exception_Name(Exception_Identity(X)).functionWide_Wide_Exception_Name (X :inException_Occurrence)returnWide_Wide_String; -- Same as Wide_Wide_Exception_Name(Exception_Identity(X)).functionException_Information (X :inException_Occurrence)returnString;procedureSave_Occurrence (Target :outException_Occurrence; Source :inException_Occurrence);functionSave_Occurrence (Source :inException_Occurrence)returnException_Occurrence_Access;procedureRead_Exception_Occurrence (Stream :notnullaccessAda.Streams.Root_Stream_Type'Class; Item :outException_Occurrence);procedureWrite_Exception_Occurrence (Stream :notnullaccessAda.Streams.Root_Stream_Type'Class; Item :inException_Occurrence);forException_Occurrence'ReaduseRead_Exception_Occurrence;forException_Occurrence'WriteuseWrite_Exception_Occurrence;privatepragmaImport (Ada, Exception_Id);pragmaImport (Ada, Exception_Occurrence);pragmaImport (Ada, Null_Id);pragmaImport (Ada, Null_Occurrence);endAda.Exceptions;
外部示例
[編輯原始碼]- 搜尋
Ada.Exceptions的 示例:Rosetta Code, GitHub (片段), 任何 Alire 包 或 本華夏公益教科書。 - 搜尋與
Ada.Exceptions相關的 帖子:Stack Overflow, comp.lang.ada 或 任何與 Ada 相關的頁面。
FSF GNAT
- 規格:a-except.ads
- 主體:a-except.adb
drake
- 規格:a-except.ads
- 主體:a-except.adb
