Nope, it is the OS that detects the problem, obviously. So the behaviour depends on the OS and the machine architecture. The code works perfectly well under x86 Linux and Windows.
The task comment explains the circumstances under which Storage_Error can be handled.
When you call Put_Line you require much more stack than when upon a recursive call. Thus as Put_Line fails you have more stack available to return without killing the process.
So the task failure is to be attributed either to BSD (Mac OS) or to ARM. I leave the investigation up to you.
You could replace Put_Line with something like this:
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
function Recursion (Depth : Positive) return Positive is
begin
declare
Garbage : String (1..80); -- Reduce the number until it fails
begin
return Recursion (Depth + 1);
end;
exception
when Storage_Error =>
return Depth;
end Recursion;
begin
Put_Line ("Recursion depth on this system is" & Integer'Image (Recursion (1)));
end Test;