111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT RUN-TIME COMPONENTS --
|
|
4 -- --
|
|
5 -- G N A T . E X C E P T I O N S --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
131
|
9 -- Copyright (C) 2000-2018, AdaCore --
|
111
|
10 -- --
|
|
11 -- GNAT is free software; you can redistribute it and/or modify it under --
|
|
12 -- terms of the GNU General Public License as published by the Free Soft- --
|
|
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
|
|
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
|
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
|
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
|
|
17 -- --
|
|
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
|
|
19 -- additional permissions described in the GCC Runtime Library Exception, --
|
|
20 -- version 3.1, as published by the Free Software Foundation. --
|
|
21 -- --
|
|
22 -- You should have received a copy of the GNU General Public License and --
|
|
23 -- a copy of the GCC Runtime Library Exception along with this program; --
|
|
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
|
25 -- <http://www.gnu.org/licenses/>. --
|
|
26 -- --
|
|
27 -- GNAT was originally developed by the GNAT team at New York University. --
|
|
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
29 -- --
|
|
30 ------------------------------------------------------------------------------
|
|
31
|
|
32 -- This package provides an interface for raising predefined exceptions
|
|
33 -- with an exception message. It can be used from Pure units.
|
|
34
|
|
35 -- There is no prohibition in Ada that prevents exceptions being raised
|
|
36 -- from within pure units. The raise statement is perfectly acceptable.
|
|
37
|
|
38 -- However, it is not normally possible to raise an exception with a
|
|
39 -- message because the routine Ada.Exceptions.Raise_Exception is not in
|
|
40 -- a Pure unit. This is an annoying and unnecessary restriction and this
|
|
41 -- package allows for raising the standard predefined exceptions at least.
|
|
42
|
|
43 package GNAT.Exceptions is
|
|
44 pragma Pure;
|
|
45
|
|
46 type Exception_Type is limited null record;
|
|
47 -- Type used to specify which exception to raise
|
|
48
|
|
49 -- Really Exception_Type is Exception_Id, but Exception_Id can't be
|
|
50 -- used directly since it is declared in the non-pure unit Ada.Exceptions,
|
|
51
|
|
52 -- Exception_Id is in fact simply a pointer to the type Exception_Data
|
|
53 -- declared in System.Standard_Library (which is also non-pure). So what
|
|
54 -- we do is to define it here as a by reference type (any by reference
|
|
55 -- type would do), and then Import the definitions from Standard_Library.
|
|
56 -- Since this is a by reference type, these will be passed by reference,
|
|
57 -- which has the same effect as passing a pointer.
|
|
58
|
|
59 -- This type is not private because keeping it by reference would require
|
|
60 -- defining it in a way (e.g. using a tagged type) that would drag in other
|
|
61 -- run-time files, which is unwanted in the case of e.g. Ravenscar where we
|
|
62 -- want to minimize the number of run-time files needed by default.
|
|
63
|
|
64 CE : constant Exception_Type; -- Constraint_Error
|
|
65 PE : constant Exception_Type; -- Program_Error
|
|
66 SE : constant Exception_Type; -- Storage_Error
|
|
67 TE : constant Exception_Type; -- Tasking_Error
|
|
68 -- One of these constants is used in the call to specify the exception
|
|
69
|
|
70 procedure Raise_Exception (E : Exception_Type; Message : String);
|
|
71 pragma Import (Ada, Raise_Exception, "__gnat_raise_exception");
|
|
72 pragma No_Return (Raise_Exception);
|
|
73 -- Raise specified exception with specified message
|
|
74
|
|
75 private
|
|
76 pragma Import (C, CE, "constraint_error");
|
|
77 pragma Import (C, PE, "program_error");
|
|
78 pragma Import (C, SE, "storage_error");
|
|
79 pragma Import (C, TE, "tasking_error");
|
|
80 -- References to the exception structures in the standard library
|
|
81
|
|
82 end GNAT.Exceptions;
|