Ada 编程/库/Ada.Exceptions
外观
此语言功能从 Ada 95 开始可用。
Ada.Exceptions 是自 Ada 95 以来 预定义语言环境 的一个单元。
包 Ada.Exceptions 允许您分析已捕获的异常,以关联消息引发异常或保存异常事件以供以后处理。
以下示例展示了如何实现一个“最后手段”错误处理程序,它只显示与发生的错误相关的信息。
with
Ada.Exceptions;procedure
Numeric_6is
package
Exeptrenames
Ada.Exceptions; ...exception
when
An_Exception :others
=> T_IO.Put_Line (Exept.Exception_Information (An_Exception));end
Try;
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <[email protected]> -- 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 -- -------------------------------------------------------------------------with
Ada.Streams;package
Ada.Exceptionsis
pragma
Preelaborate (Exceptions);type
Exception_Idis
private
;pragma
Preelaborable_Initialization (Exception_Id); Null_Id :constant
Exception_Id;function
Exception_Name (Id :in
Exception_Id)return
String;function
Wide_Exception_Name (Id :in
Exception_Id)return
Wide_String;function
Wide_Wide_Exception_Name (Id :in
Exception_Id)return
Wide_Wide_String;type
Exception_Occurrenceis
limited
private
;pragma
Preelaborable_Initialization (Exception_Occurrence);type
Exception_Occurrence_Accessis
access
all
Exception_Occurrence; Null_Occurrence :constant
Exception_Occurrence;procedure
Raise_Exception (E :in
Exception_Id; Message :in
String := "");pragma
No_Return (Raise_Exception);function
Exception_Message (X :in
Exception_Occurrence)return
String;procedure
Reraise_Occurrence (X :in
Exception_Occurrence);function
Exception_Identity (X :in
Exception_Occurrence)return
Exception_Id;function
Exception_Name (X :in
Exception_Occurrence)return
String; -- Same as Exception_Name(Exception_Identity(X)).function
Wide_Exception_Name (X :in
Exception_Occurrence)return
Wide_String; -- Same as Wide_Exception_Name(Exception_Identity(X)).function
Wide_Wide_Exception_Name (X :in
Exception_Occurrence)return
Wide_Wide_String; -- Same as Wide_Wide_Exception_Name(Exception_Identity(X)).function
Exception_Information (X :in
Exception_Occurrence)return
String;procedure
Save_Occurrence (Target :out
Exception_Occurrence; Source :in
Exception_Occurrence);function
Save_Occurrence (Source :in
Exception_Occurrence)return
Exception_Occurrence_Access;procedure
Read_Exception_Occurrence (Stream :not
null
access
Ada.Streams.Root_Stream_Type'Class; Item :out
Exception_Occurrence);procedure
Write_Exception_Occurrence (Stream :not
null
access
Ada.Streams.Root_Stream_Type'Class; Item :in
Exception_Occurrence);for
Exception_Occurrence'Readuse
Read_Exception_Occurrence;for
Exception_Occurrence'Writeuse
Write_Exception_Occurrence;private
pragma
Import (Ada, Exception_Id);pragma
Import (Ada, Exception_Occurrence);pragma
Import (Ada, Null_Id);pragma
Import (Ada, Null_Occurrence);end
Ada.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