Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch Precondition Assert_Failure

Tags:

ada

I'm trying to catch the error in this precondition I have on the main procedure and I'm wondering if it's possible to catch? Do I need to move this to a different procedure and then call it in main in order to catch it?

 with
    ada.text_io,
    ada.command_line,
    ada.strings.bounded,
    system.assertions;

 procedure main with
    pre => (ada.command_line.argument_count > 2)
 is
    package b_str is new
        ada.strings.bounded.generic_bounded_length (max => 255);
    use b_str;

    input_file : bounded_string;
    argument : bounded_string;
    i : integer := 1;
 begin
    while i <= ada.command_line.argument_count loop
        argument := to_bounded_string(
            ada.command_line.argument(i)
        );

         ada.text_io.put_line("[" & i'image & "] "
            & to_string(argument)
        );

        i := i + 1;
    end loop;
 exception
    when system.assertions.assert_failure =>
        ada.text_io.put_line("Failed precondition");
 end main;
like image 870
jacob Avatar asked Mar 24 '26 15:03

jacob


1 Answers

I've found my answer:

Exception handlers have an important restriction that you need to be careful about: Exceptions raised in the declarative section are not caught by the handlers of that block.

From: https://learn.adacore.com/courses/intro-to-ada/chapters/exceptions.html

like image 146
jacob Avatar answered Mar 27 '26 19:03

jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!