Content deleted Content added
→[[Ada (programming language)|Ada]]: declaration and raising - should be added to the other langauges as well... |
|||
Line 4:
=== [[Ada (programming language)|Ada]] ===
{{wikibooks|Ada Programming|Exceptions}}
==== Exception declarations ====
Some_Error : '''exception''';
==== Raising exceptions ====
'''raise''' Some_Error '''with''' "Out of memory";
==== Exception handling and propagation ====
with Ada.Exceptions; use Ada.Exceptions;
'''procedure''' Foo '''is'''
'''begin'''
Do_Something_Interesting;
'''exception'''
'''when''' Constraint_Error =>
''-- Handle constraint error''
'''when''' Storage_Error =>
''-- Propagate the Storage_Error as different exception with some useful message''
'''raise''' Some_Error '''with''' "Out of memory";
'''when''' Error : '''others''' =>
''-- Handle all others''
Put ("Exception: ");
Put_Line (Exception_Name (Error));
Put (Exception_Message (Error));
'''end''' Foo;
For a more complete discussion of exceptions in Ada see [[:Wikibooks:Ada Programming/Exceptions|the wikibook on Ada]].
|