File 1344-kernel-test-Replaced-use-of-catch-with-try-catch-soc.patch of Package erlang

From eef6a7803dbb5523e69a582281b277e4ae4de128 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Wed, 4 Mar 2026 08:41:15 +0100
Subject: [PATCH 4/8] [kernel|test] Replaced use of 'catch' with 'try catch'
 (socket)

---
 lib/kernel/test/socket_SUITE.erl         | 139 ++++++++++++++---------
 lib/kernel/test/socket_api_SUITE.erl     |  94 +++++++--------
 lib/kernel/test/socket_traffic_SUITE.erl |  54 ++++-----
 lib/kernel/test/socket_ttest_SUITE.erl   |   6 +-
 4 files changed, 160 insertions(+), 133 deletions(-)

diff --git a/lib/kernel/test/socket_SUITE.erl b/lib/kernel/test/socket_SUITE.erl
index b4955723c3..0d2c04654b 100644
--- a/lib/kernel/test/socket_SUITE.erl
+++ b/lib/kernel/test/socket_SUITE.erl
@@ -66,8 +66,6 @@
 %% Some official info about AF_UNIX
 %% https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/
 
-
-
 -module(socket_SUITE).
 
 -include_lib("common_test/include/ct.hrl").
@@ -496,7 +494,8 @@ end_per_suite(Config0) ->
     %% Stop the local monitor
     kernel_test_sys_monitor:stop(),
 
-    (catch ?LOGGER:stop()),
+    ?CATCH_AND_IGNORE( ?LOGGER:stop() ),
+    %%(catch ?LOGGER:stop()),
 
     Config1 = ?KLIB:end_per_suite(Config0),
 
@@ -509,9 +508,8 @@ end_per_suite(Config0) ->
 init_per_group(GroupName, Config)
   when (GroupName =:= sc_remote_close) orelse
        (GroupName =:= sc_remote_shutdown) ->
-    io:format("init_per_group(~w) -> entry with"
-              "~n   Config: ~p"
-              "~n", [GroupName, Config]),
+    ?P("~s(~w) -> entry with"
+       "~n   Config: ~p", [?FUNCTION_NAME, GroupName, Config]),
     %% Maybe we should skip the entire suite for this platform,
     %% but for now we just skip these groups, which seem to 
     %% have problems (node start).
@@ -526,17 +524,17 @@ init_per_group(GroupName, Config)
     end;
 init_per_group(GroupName, Config)
   when (GroupName =:= ioctl) ->
-    io:format("init_per_group(~w) -> entry with"
-              "~n   Config:"
-              "~n      ~p"
-              "~nwhen"
-              "~n   Supported IOCtl Requests: "
-              "~n~s"
-              "~n   Supported IOCtl Flags: "
-              "~n~s"
-              "~n", [GroupName, Config,
-                     format_ioctls(socket:supports(ioctl_requests), 6),
-                     format_ioctls(socket:supports(ioctl_flags), 6)]),
+    ?P("~s(~w) -> entry with"
+       "~n   Config:"
+       "~n      ~p"
+       "~nwhen"
+       "~n   Supported IOCtl Requests: "
+       "~n~s"
+       "~n   Supported IOCtl Flags: "
+       "~n~s", [?FUNCTION_NAME,
+		GroupName, Config,
+		format_ioctls(socket:supports(ioctl_requests), 6),
+		format_ioctls(socket:supports(ioctl_flags), 6)]),
     Config;
 init_per_group(_GroupName, Config) ->
     Config.
@@ -629,27 +627,39 @@ reg_s_single_open_and_close_and_count() ->
     %% Make sure we dont count them when we test.
     Existing = socket:which_sockets(),
     N = length(Existing),
-    SupportsIPV6 =
-        case (catch has_support_ipv6()) of
-            ok ->
-                true;
-            _ ->
-                false
-        end,
-    SupportsLOCAL =
-        case (catch has_support_unix_domain_socket()) of
-            ok ->
-                true;
-            _ ->
-                false
-        end,
-    SupportsSCTP =
-        case (catch has_support_sctp()) of
-            ok ->
-                true;
-            _ ->
-                false
-        end,
+    HasSupport =
+	fun(F) when is_function(F, 0) ->
+		try F() of
+		    ok ->
+			true;
+		    _ ->
+			false
+		catch
+		    _:_ ->
+			false
+		end
+	end,
+    SupportsIPV6 = HasSupport(fun has_support_ipv6/0),
+        %% try has_support_ipv6() of
+        %%     ok ->
+        %%         true;
+        %%     _ ->
+        %%         false
+        %% end,
+    SupportsLOCAL = HasSupport(fun has_support_unix_domain_socket/0),
+        %% case (catch has_support_unix_domain_socket()) of
+        %%     ok ->
+        %%         true;
+        %%     _ ->
+        %%         false
+        %% end,
+    SupportsSCTP = HasSupport(fun has_support_sctp/0),
+        %% case (catch has_support_sctp()) of
+        %%     ok ->
+        %%         true;
+        %%     _ ->
+        %%         false
+        %% end,
     InitSockInfos =
         [
          {inet, stream, tcp},
@@ -692,7 +702,8 @@ reg_s_single_open_and_close_and_count() ->
                                  #{use_registry => false}) of
                     {ok, S} ->
                         ?P("test open sctp socket: success"),
-                        (catch socket:close(S)),
+                        ?CATCH_AND_IGNORE( socket:close(S) ),
+                        %% (catch socket:close(S)),
                         [
                          {inet, seqpacket, sctp},
                          {inet, seqpacket, sctp}
@@ -719,7 +730,8 @@ reg_s_single_open_and_close_and_count() ->
                                  #{use_registry => false}) of
                     {ok, S6} ->
                         ?P("test open sctp socket: success"),
-                        (catch socket:close(S6)),
+                        ?CATCH_AND_IGNORE( socket:close(S6) ),
+                        %% (catch socket:close(S6)),
                         [
                          {inet6, seqpacket, sctp},
                          {inet6, seqpacket, sctp}
@@ -5778,7 +5790,8 @@ mon_closed_socket(InitState) ->
            cmd  => fun(#{tester := Tester,
 			 sock   := Sock} = State) ->
                            ?SEV_ANNOUNCE_READY(Tester, init, Sock),
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                           %% (catch socket:close(Sock)),
                            {ok, maps:remove(sock, State)}
                    end},
 
@@ -7060,7 +7073,8 @@ sc_lc_receive_response_udp(InitState) ->
                                {error, eafnosupport = Reason} ->
                                    ?SEV_IPRINT("Failed get socket name: "
                                                "~n   ~p", [Reason]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   %% (catch socket:close(Sock)),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Failed get socket name: "
@@ -7666,7 +7680,8 @@ sc_lc_acceptor_response_tcp(InitState) ->
                                    ok;
                                {ok, Sock} ->
                                    ?SEV_EPRINT("unexpected success"),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   %% (catch socket:close(Sock)),
                                    {error, unexpected_success};
                                {error, _} = ERROR ->
                                    ERROR
@@ -11993,35 +12008,41 @@ otp18240_client(ID, Domain, Proto, Addr, PortNo) ->
                 {ok, Data} ->
                     i("[connector ~w] received unexpected data: "
                       "~n   ~p", [ID, Data]),
-                    (catch socket:close(Sock)),
+                    ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                    %% (catch socket:close(Sock)),
                     exit('unexpected data');
                 {error, closed} ->
                     i("[connector ~w] expected socket close", [ID]);
                 {error, Reason} ->
                     i("[connector ~w] unexpected error when reading: "
                       "~n   ~p", [ID, Reason]),
-                    (catch socket:close(Sock))
+                    ?CATCH_AND_IGNORE( socket:close(Sock) )
+		    %% (catch socket:close(Sock))
             end;
         {error, {completion_status, #{info := invalid_netname = R} = Reason}} ->
             i("[connector ~w] failed connecting: "
               "~n   ~p", [ID, Reason]),
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
+            %% (catch socket:close(Sock)),
             exit({skip, R});
         {error, {completion_status, invalid_netname = Reason}} ->
             i("[connector ~w] failed connecting: "
               "~n   ~p", [ID, Reason]),
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
+            %% (catch socket:close(Sock)),
             exit({skip, Reason});
         {error, enetunreach = Reason} ->
             i("[connector ~w] failed connecting: "
               "~n   ~p", [ID, Reason]),
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
+            %% (catch socket:close(Sock)),
             exit({skip, Reason});
 
         {error, Reason} ->
             i("[connector ~w] failed connecting: "
               "~n   ~p", [ID, Reason]),
-            (catch socket:close(Sock))
+            ?CATCH_AND_IGNORE( socket:close(Sock) )
+	    %% (catch socket:close(Sock))
     end,
     i("[connector ~w] done", [ID]),
     ok.
@@ -12138,7 +12159,8 @@ do_otp18635(_) ->
                   receive
                       {Parent, terminate} ->
                           ?P("[connector] terminate - close socket"),
-                          (catch socket:close(CSock)),
+                          ?CATCH_AND_IGNORE( socket:close(CSock) ),
+                          %% (catch socket:close(CSock)),
                           exit(normal)
                   end
           end),
@@ -12276,7 +12298,8 @@ do_otp19063(_) ->
                   receive
                       {Parent, terminate} ->
                           ?P("[connector] terminate - close socket"),
-                          (catch socket:close(CSock1)),
+                          ?CATCH_AND_IGNORE( socket:close(CSock1) ),
+                          %% (catch socket:close(CSock1)),
                           exit(normal)
                   end
           end),
@@ -13032,7 +13055,8 @@ do_otp19482_simple_single(#{n       := N,
                           end,
 
                           ?P("[client] close socket"),
-                          (catch socket:close(CSock)),
+                          ?CATCH_AND_IGNORE( socket:close(CSock) ),
+                          %% (catch socket:close(CSock)),
                           ?P("[client] terminate"),
                           exit(normal)
                   end
@@ -13200,7 +13224,8 @@ otp19482_simple_single_server_exchange(Sock, Verify, Sz, N) ->
 	       "~n   sz(BadData): ~w"
 	       "~n   info(Sock):  ~p",
 	       [N, Sz, byte_size(BadData), socket:info(Sock)]),
-	    (catch Verify(BadData)),
+	    ?CATCH_AND_IGNORE( Verify(BadData) ),
+	    %% (catch Verify(BadData)),
 	    ?FAIL({unexpected_recv_result, timeout});
 	{error, {Reason, Data}} ->
 	    ?P("[server,~w] receive failed with data: "
@@ -13752,7 +13777,8 @@ otp19482_simple_multi_client_init(Parent, ID, LSA, Port, IOV) ->
             end,
 
             ?P("C[~w] -> close socket", [ID]),
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
+            %% (catch socket:close(Sock)),
             ?P("C[~w] -> terminate", [ID]),
             exit(normal)
     end.
@@ -13988,7 +14014,8 @@ do_otp19482_async_simple_single(#{iov_max := IOVMax,
                           end,
 
                           ?P("[client] close socket"),
-                          (catch socket:close(CSock)),
+                          ?CATCH_AND_IGNORE( socket:close(CSock) ),
+                          %% (catch socket:close(CSock)),
                           ?P("[client] terminate"),
                           exit(normal)
                   end
diff --git a/lib/kernel/test/socket_api_SUITE.erl b/lib/kernel/test/socket_api_SUITE.erl
index a5f11c9021..86a1d66f90 100644
--- a/lib/kernel/test/socket_api_SUITE.erl
+++ b/lib/kernel/test/socket_api_SUITE.erl
@@ -724,7 +724,7 @@ end_per_suite(Config0) ->
     %% Stop the local monitor
     kernel_test_sys_monitor:stop(),
 
-    (catch ?LOGGER:stop()),
+    ?CATCH_AND_IGNORE( ?LOGGER:stop() ),
 
     Config1 = ?KLIB:end_per_suite(Config0),
 
@@ -2273,7 +2273,7 @@ api_b_send_and_recv_conn(InitState) ->
                                       "~n   Expected: (~w bytes) ~p",
                                       [byte_size(BadReq), BadReq,
                                        byte_size(?BASIC_REQ), ?BASIC_REQ]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    ?FAIL({unexpected_request, BadReq});
                                {error, _} = ERROR ->
                                    ERROR
@@ -12309,7 +12309,7 @@ api_opt_sock_acceptconn_udp() ->
                                    %% for UDP, so skip this part (UDP).
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Unexpected Failure: ~p",
@@ -12452,7 +12452,7 @@ api_opt_sock_acceptconn_tcp() ->
                                {error, enoprotoopt = Reason} ->
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Unexpected Failure: ~p",
@@ -12897,7 +12897,7 @@ api_opt_sock_bindtodevice() ->
                                    ok;
                                {error, eperm = Reason} ->
                                    ?SEV_IPRINT("Expected Failure: ~p", [Reason]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {ok, State#{usock1 => skip}};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Unexpected Failure: ~p", [Reason]),
@@ -12927,7 +12927,7 @@ api_opt_sock_bindtodevice() ->
                                    {skip, Reason};
                                {error, eperm = Reason} ->
                                    ?SEV_IPRINT("Expected Failure: ~p", [Reason]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {ok, State#{tsock1 => skip}};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Unexpected Failure: ~p", [Reason]),
@@ -20895,8 +20895,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                    %% IF we can't send it the test will not work
                                    ?SEV_EPRINT("Cannot send TTL: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip,
 				    ?F("Cannot send with TTL: ~p", [Reason])};
                                {error, enoprotoopt = Reason} ->
@@ -20904,8 +20904,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                    %% accepted (FreeBSD), so skip.
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip, Reason};
 
                                {error,
@@ -20925,8 +20925,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                                [Info,
                                                 File, Function, Line,
                                                 RawInfo]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip,
                                     ?F("Cannot send with TTL: ~p", [Info])};
                                {error, {get_overlapped_result,
@@ -20934,8 +20934,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                    %% IF we can't send it the test will not work
                                    ?SEV_EPRINT("Cannot send TTL: "
                                                "~p => SKIP", [Info]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip,
                                     ?F("Cannot send with TTL: ~p", [Info])};
 
@@ -20956,8 +20956,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                                [Info,
                                                 File, Function, Line,
                                                 RawInfo]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip,
                                     ?F("Cannot send with TTL: ~p", [Info])};
                                {error, {completion_status,
@@ -20965,8 +20965,8 @@ api_opt_ip_recvttl_udp(InitState) ->
                                    %% IF we can't send it the test will not work
                                    ?SEV_EPRINT("Cannot send TTL: "
                                                "~p => SKIP", [Info]),
-                                   (catch socket:close(SSock)),
-                                   (catch socket:close(DSock)),
+                                   ?CATCH_AND_IGNORE( socket:close(SSock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(DSock) ),
                                    {skip,
                                     ?F("Cannot send with TTL: ~p", [Info])};
 
@@ -22120,8 +22120,8 @@ api_opt_ip_mopts_udp(InitState) ->
                                                            "Failure: "
                                                            "~p => SKIP",
                                                            [Reason]),
-                                               (catch socket:close(DSock)),
-                                               (catch socket:close(SSock)),
+                                               ?CATCH_AND_IGNORE( socket:close(DSock) ),
+                                               ?CATCH_AND_IGNORE( socket:close(SSock) ),
                                                {skip, Reason};
                                            {error, Reason} = ERROR ->
                                                ?SEV_EPRINT("Failed "
@@ -22869,9 +22869,9 @@ api_opt_ipv6_hoplimit_udp(InitState) ->
                                    %% for UDP, so skip this part (UDP).
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
-                                   (catch socket:close(maps:get_value(sock_src,
-								      State))),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(maps:get_value(sock_src,
+										  State)) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Failed getting (default) hoplimit:"
@@ -22927,9 +22927,9 @@ api_opt_ipv6_hoplimit_udp(InitState) ->
                                    %% for UDP, so skip this part (UDP).
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
-                                   (catch socket:close(maps:get_value(sock_src,
-								      State))),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(maps:get_value(sock_src,
+										  State)) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Failed setting hoplimit:"
@@ -23163,9 +23163,9 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                    %% for UDP, so skip this part (UDP).
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
-                                   (catch socket:close(maps:get_value(sock_src,
-								      State))),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(maps:get_value(sock_src,
+										  State)) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Failed getting (default) tclass:"
@@ -23221,9 +23221,9 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                    %% for UDP, so skip this part (UDP).
                                    ?SEV_EPRINT("Expected Failure: "
                                                "~p => SKIP", [Reason]),
-                                   (catch socket:close(Sock)),
-                                   (catch socket:close(maps:get_value(sock_src,
-								      State))),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
+                                   ?CATCH_AND_IGNORE( socket:close(maps:get_value(sock_src,
+										  State)) ),
                                    {skip, Reason};
                                {error, Reason} = ERROR ->
                                    ?SEV_EPRINT("Failed setting tclass:"
@@ -23299,7 +23299,7 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                                [Info,
                                                 File, Function, Line,
                                                 RawInfo]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip,
                                     ?F("Cannot send with TClass: ~p", [Info])};
                                {error, {get_overlapped_result,
@@ -23307,7 +23307,7 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                    %% IF we can't send it the test will not work
                                    ?SEV_EPRINT("Cannot send TClass: "
                                                "~p => SKIP", [Info]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip,
                                     ?F("Cannot send with TClass: ~p", [Info])};
 
@@ -23328,7 +23328,7 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                                [Info,
                                                 File, Function, Line,
                                                 RawInfo]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip,
                                     ?F("Cannot send with TClass: ~p", [Info])};
                                {error, {completion_status,
@@ -23336,7 +23336,7 @@ api_opt_ipv6_tclass_udp(InitState) ->
                                    %% IF we can't send it the test will not work
                                    ?SEV_EPRINT("Cannot send TClass: "
                                                "~p => SKIP", [Info]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {skip,
                                     ?F("Cannot send with TClass: ~p", [Info])};
 
@@ -23650,8 +23650,8 @@ api_opt_ipv6_mopts_udp(InitState) ->
                                                            "Failure: "
                                                            "~p => SKIP",
                                                            [Reason]),
-                                               (catch socket:close(DSock)),
-                                               (catch socket:close(SSock)),
+                                               ?CATCH_AND_IGNORE( socket:close(DSock) ),
+                                               ?CATCH_AND_IGNORE( socket:close(SSock) ),
                                                {skip, Reason};
                                            {error, Reason} = ERROR ->
                                                ?SEV_EPRINT("Failed "
@@ -25788,17 +25788,17 @@ api_to_connect_tcp_await_timeout2(_ID, To, ServerSA, NewSock) ->
             TDiff = Stop - Start,
             if
                 (TDiff >= To) ->
-                    (catch socket:close(Sock)),
+                    ?CATCH_AND_IGNORE( socket:close(Sock) ),
                     ok;
                 true ->
-                    (catch socket:close(Sock)),
+                    ?CATCH_AND_IGNORE( socket:close(Sock) ),
                     ?FAIL({unexpected_timeout, TDiff, To})
             end;
         {error, econnreset = _Reason} ->
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
             ok;
         {error, Reason} ->
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
             ?FAIL({connect, Reason});
         ok ->
             {ok, Sock}
@@ -25807,7 +25807,7 @@ api_to_connect_tcp_await_timeout2(_ID, To, ServerSA, NewSock) ->
 api_to_connect_tcp_await_timeout3([]) ->
     ok;
 api_to_connect_tcp_await_timeout3([Sock|Socka]) ->
-    (catch socket:close(Sock)),
+    ?CATCH_AND_IGNORE( socket:close(Sock) ),
     api_to_connect_tcp_await_timeout3(Socka).
 
 
@@ -25881,7 +25881,7 @@ api_to_accept_tcp(InitState) ->
                                {error, timeout} ->
                                    {ok, State#{start => Start, stop => ?TS()}};
                                {ok, Sock} ->
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {error, unexpected_success};
                                {error, _} = ERROR ->
                                    ERROR
@@ -26009,7 +26009,7 @@ api_to_maccept_tcp(InitState) ->
                                {ok, Sock} ->
                                    ?SEV_EPRINT("Unexpected accept success: "
                                                "~n   ~p", [Sock]),
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {error, unexpected_success};
                                {error, _} = ERROR ->
                                    ERROR
@@ -26082,7 +26082,7 @@ api_to_maccept_tcp(InitState) ->
                                {error, timeout} ->
                                    {ok, State#{start => Start, stop => ?TS()}};
                                {ok, Sock} ->
-                                   (catch socket:close(Sock)),
+                                   ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                    {error, unexpected_success};
                                {error, _} = ERROR ->
                                    ERROR
diff --git a/lib/kernel/test/socket_traffic_SUITE.erl b/lib/kernel/test/socket_traffic_SUITE.erl
index ed5e56ca30..f67f6124b5 100644
--- a/lib/kernel/test/socket_traffic_SUITE.erl
+++ b/lib/kernel/test/socket_traffic_SUITE.erl
@@ -3,7 +3,7 @@
 %%
 %% SPDX-License-Identifier: Apache-2.0
 %% 
-%% Copyright Ericsson AB 2024-2025. All Rights Reserved.
+%% Copyright Ericsson AB 2024-2026. All Rights Reserved.
 %% 
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -411,7 +411,7 @@ end_per_suite(Config0) ->
     %% Stop the local monitor
     kernel_test_sys_monitor:stop(),
 
-    (catch ?LOGGER:stop()),
+    ?CATCH_AND_IGNORE( ?LOGGER:stop() ),
 
     Config1 = ?KLIB:end_per_suite(Config0),
 
@@ -1096,7 +1096,7 @@ traffic_send_and_recv_stream(InitState) ->
                    end},
          #{desc => "close connection socket (just in case)",
            cmd  => fun(#{csock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(csock, State)}
                    end},
          #{desc => "close listen socket",
@@ -1112,7 +1112,7 @@ traffic_send_and_recv_stream(InitState) ->
                                            fun() -> State end),
                            {ok, maps:remove(lsock, State1)};
                       (#{lsock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(lsock, State)}
                    end},
 
@@ -1746,12 +1746,12 @@ traffic_sar_counters_validation(Counters, ValidateCounters) ->
 traffic_sar_counters_validation2(Counters, []) ->
     %% ?SEV_IPRINT("traffic_sar_counters_validation2 -> Remaining Counters: "
     %%             "~n   ~p", [Counters]),
-    (catch lists:foreach(
-             fun({_Cnt, 0})   -> ok;
-                ({Cnt,  Val}) ->
-                     throw({error, {invalid_counter, Cnt, Val}})
-             end,
-             Counters));
+    ?CATCH_AND_RETURN( lists:foreach(
+			 fun({_Cnt, 0})   -> ok;
+			    ({Cnt,  Val}) ->
+				 throw({error, {invalid_counter, Cnt, Val}})
+			 end,
+			 Counters) );
 traffic_sar_counters_validation2(Counters, [{Cnt, Val}|ValidateCounters]) ->
     %% ?SEV_IPRINT("traffic_sar_counters_validation2 -> try validate ~w when"
     %%             "~n   Counters:         ~p"
@@ -2255,7 +2255,7 @@ traffic_send_and_recv_udp(InitState) ->
                                            fun() -> State end),
                            {ok, maps:remove(lsock, State1)};
                       (#{sock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(sock, State)}
                    end},
 
@@ -3166,7 +3166,7 @@ traffic_send_and_recv_chunks_stream(InitState) ->
                    end},
          #{desc => "close connection socket (just in case)",
            cmd  => fun(#{csock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(csock, State)}
                    end},
          #{desc => "close listen socket",
@@ -3182,7 +3182,7 @@ traffic_send_and_recv_chunks_stream(InitState) ->
                                            fun() -> State end),
                            {ok, maps:remove(lsock, State1)};
                       (#{lsock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(lsock, State)}
                    end},
 
@@ -5409,7 +5409,7 @@ traffic_ping_pong_send_and_receive_stream2(InitState) ->
            cmd  => fun(#{domain   := local,
                          lsock    := Sock,
                          local_sa := #{path := Path}} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            State1 =
                                unlink_path(Path,
                                            fun() -> 
@@ -5418,7 +5418,7 @@ traffic_ping_pong_send_and_receive_stream2(InitState) ->
                                            fun() -> State end),
                            {ok, maps:remove(lsock, State1)};
                       (#{lsock := Sock} = State) ->
-                           (catch socket:close(Sock)),
+                           ?CATCH_AND_IGNORE( socket:close(Sock) ),
                            {ok, maps:remove(lsock, State)}
                    end},
 
@@ -7395,27 +7395,27 @@ tb_server_loop(#{listen := LS, accept := AS, send := Send} = State) ->
                         {error, SReason} ->
                             ?SEV_EPRINT("[server] unexpected send error:"
                                         "~n   ~p", [SReason]),
-                            (catch socket:close(LS)),
-                            (catch socket:close(AS)),
+                            ?CATCH_AND_IGNORE( socket:close(LS) ),
+                            ?CATCH_AND_IGNORE( socket:close(AS) ),
                             exit({tb_server_send, SReason})
                     end;
                 {error, R2Reason} ->
                     ?SEV_EPRINT("[server] unexpected read (data) error:"
                                 "~n   ~p", [R2Reason]),
-                    (catch socket:close(LS)),
-                    (catch socket:close(AS)),
+                    ?CATCH_AND_IGNORE( socket:close(LS) ),
+                    ?CATCH_AND_IGNORE( socket:close(AS) ),
                     exit({tb_server_recv2, R2Reason})
             end;
         {error, closed} ->
             ?SEV_IPRINT("[server] socket closed => terminate"),
-            (catch socket:close(LS)),
-            (catch socket:close(AS)),
+            ?CATCH_AND_IGNORE( socket:close(LS) ),
+            ?CATCH_AND_IGNORE( socket:close(AS) ),
             exit(normal);
         {error, R1Reason} ->
             ?SEV_EPRINT("[server] unexpected read (sz) error:"
                         "~n   ~p", [R1Reason]),
-            (catch socket:close(LS)),
-            (catch socket:close(AS)),
+            ?CATCH_AND_IGNORE( socket:close(LS) ),
+            ?CATCH_AND_IGNORE( socket:close(AS) ),
             exit({tb_server_recv1, R1Reason})
     end.                    
 
@@ -7491,7 +7491,7 @@ tb_client_loop(Pid, Sock, Send, Data0, TStart, ARcv0, N0) ->
                                                 [TDiff, ARcv,
                                                  Exchange, UnitStr,
                                                  N]),
-                                    (catch socket:close(Sock)),
+                                    ?CATCH_AND_IGNORE( socket:close(Sock) ),
                                     exit({done, Res});
                                 false ->
                                     IOV = [SzBin | IOV0],
@@ -7504,19 +7504,19 @@ tb_client_loop(Pid, Sock, Send, Data0, TStart, ARcv0, N0) ->
                         {error, R2Reason} ->
                             ?SEV_EPRINT("[client] unexpected read (data) error:"
                                         "~n   ~p", [R2Reason]),
-                            (catch socket:close(Sock)),
+                            ?CATCH_AND_IGNORE( socket:close(Sock) ),
                             exit({tb_client_recv2, R2Reason})
                     end;
                 {error, R1Reason} ->
                     ?SEV_EPRINT("[client] unexpected read (sz) error:"
                                 "~n   ~p", [R1Reason]),
-                    (catch socket:close(Sock)),
+                    ?CATCH_AND_IGNORE( socket:close(Sock) ),
                     exit({tb_client_recv1, R1Reason})
             end;
         {error, SReason} ->
             ?SEV_EPRINT("[client] unexpected send error:"
                         "~n   ~p", [SReason]),
-            (catch socket:close(Sock)),
+            ?CATCH_AND_IGNORE( socket:close(Sock) ),
             exit({tb_client_send, SReason})
     end.                    
 
diff --git a/lib/kernel/test/socket_ttest_SUITE.erl b/lib/kernel/test/socket_ttest_SUITE.erl
index abb906fbe0..fdf884db72 100644
--- a/lib/kernel/test/socket_ttest_SUITE.erl
+++ b/lib/kernel/test/socket_ttest_SUITE.erl
@@ -3,7 +3,7 @@
 %%
 %% SPDX-License-Identifier: Apache-2.0
 %%
-%% Copyright Ericsson AB 2024-2025. All Rights Reserved.
+%% Copyright Ericsson AB 2024-2026. All Rights Reserved.
 %%
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -2602,7 +2602,7 @@ end_per_suite(Config0) ->
     %% Stop the local monitor
     kernel_test_sys_monitor:stop(),
 
-    (catch ?LOGGER:stop()),
+    ?CATCH_AND_IGNORE( ?LOGGER:stop() ),
 
     Config1 = ?KLIB:end_per_suite(Config0),
 
@@ -12370,7 +12370,7 @@ ttest_report(Domain,
     %% If we run just one test case, the group init has never been run
     %% and therefore the ttest manager is not running (we also don't actually
     %% care about collecting reports in that case).
-    (catch global:send(?TTEST_MANAGER, Report)),
+    ?CATCH_AND_IGNORE( global:send(?TTEST_MANAGER, Report) ),
     ok.
 
 ttest_msg_id_num_to_name(1) ->
-- 
2.51.0

openSUSE Build Service is sponsored by