File 5037-kernel-test-Replaced-use-of-catch-with-try-catch-gen.patch of Package erlang

From da9659d7f0bfce355e0f7755a2edd14d4670b1e6 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Wed, 4 Mar 2026 11:00:47 +0100
Subject: [PATCH 7/8] [kernel|test] Replaced use of 'catch' with 'try catch'
 (gen udp)

---
 lib/kernel/test/gen_udp_SUITE.erl | 74 +++++++++++++++++--------------
 1 file changed, 40 insertions(+), 34 deletions(-)

diff --git a/lib/kernel/test/gen_udp_SUITE.erl b/lib/kernel/test/gen_udp_SUITE.erl
index 08f3f8db2f..e7adb4a89f 100644
--- a/lib/kernel/test/gen_udp_SUITE.erl
+++ b/lib/kernel/test/gen_udp_SUITE.erl
@@ -855,7 +855,7 @@ do_max_buffer_size(Config) when is_list(Config) ->
         {error, Reason} ->
             ?P("failed extracting buffers"
                "~n   ~p", [Reason]),
-            (catch gen_udp:close(Socket)),
+            ?CATCH_AND_IGNORE( gen_udp:close(Socket) ),
             ct:fail({unexpected_getopts_error, Reason})
     end,
     ?P("done"),
@@ -921,23 +921,27 @@ do_bad_address(Config) when is_list(Config) ->
     {ok, _SP} = inet:port(S),
 
     ?P("try send to invalid address 1 - expect failure"),
-    case (catch gen_udp:send(S, {127,0,0,1,0}, RP, "void")) of
-        {'EXIT', badarg} ->
-            ok;
+    try gen_udp:send(S, {127,0,0,1,0}, RP, "void") of
         Any1 ->
             ?P("<ERROR> unexpected result: "
                "~n   ~p", [Any1]),
-            ct:fail({unexpected_result, 1, Any1})                
+            ct:fail({unexpected_result, 1, Any1})
+    catch
+        C1:badarg ->
+	    ?P("~s -> expected (~w) catch 1", [?FUNCTION_NAME, C1]),
+            ok
     end,
 
     ?P("try send to invalid address 2 - expect failure"),
-    case (catch gen_udp:send(S, {127,0,0,256}, RP, "void")) of
-        {'EXIT', badarg} ->
-            ok;
+    try gen_udp:send(S, {127,0,0,256}, RP, "void") of
         Any2 ->
             ?P("<ERROR> unexpected result: "
                "~n   ~p", [Any2]),
             ct:fail({unexpected_result, 2, Any2})
+    catch
+        C2:badarg ->
+	    ?P("~s -> expected (~w) catch 2", [?FUNCTION_NAME, C2]),
+            ok
     end,
 
     ?P("cleanup"),
@@ -1268,8 +1274,8 @@ do_open_fd(Config) when is_list(Config) ->
         {ok, Socket} ->
             ?P("unexpected success: "
                "~n   ~p", [inet:info(Socket)]),
-            (catch gen_udp:close(Socket)),
-            (catch gen_udp:close(S1)),
+            ?CATCH_AND_IGNORE( gen_udp:close(Socket) ),
+            ?CATCH_AND_IGNORE( gen_udp:close(S1) ),
             case ((OS =:= darwin) andalso ?IS_SOCKET_BACKEND(Config)) of
                 true ->
                     %% This should not work, but on (some) Darwin
@@ -1315,9 +1321,9 @@ do_open_fd(Config) when is_list(Config) ->
 	    ct:fail(io_lib:format("~w", [flush()]))
     end,
     ?P("cleanup"),
-    (catch gen_udp:close(S3)),
-    (catch gen_udp:close(S2)),
-    (catch gen_udp:close(S1)),
+    ?CATCH_AND_IGNORE( gen_udp:close(S3) ),
+    ?CATCH_AND_IGNORE( gen_udp:close(S2) ),
+    ?CATCH_AND_IGNORE( gen_udp:close(S1) ),
     ?P("done"),
     ok.
 
@@ -2935,7 +2941,7 @@ do_otp_17492(Config) ->
 	    ?P("(created) socket info: ~p", [Info]);
 	OBadInfo ->
 	    ?P("(created) socket info: ~p", [OBadInfo]),
-	    (catch gen_udp:close(L)),
+	    ?CATCH_AND_IGNORE( gen_udp:close(L) ),
 	    ct:fail({invalid_created_info, OBadInfo})
     catch
 	OC:OE:OS ->
@@ -2943,7 +2949,7 @@ do_otp_17492(Config) ->
 	       "~n   Class: ~p"
 	       "~n   Error: ~p"
 	       "~n   Stack: ~p", [OC, OE, OS]),
-	    (catch gen_udp:close(L)),
+	    ?CATCH_AND_IGNORE( gen_udp:close(L) ),
 	    ct:fail({unexpected_created_info_result, {OC, OE, OS}})
     end,
 
@@ -2967,7 +2973,7 @@ do_otp_17492(Config) ->
 	       "~n   Class: ~p"
 	       "~n   Error: ~p"
 	       "~n   Stack: ~p", [CC, CE, CS]),
-	    (catch gen_udp:close(L)),
+	    ?CATCH_AND_IGNORE( gen_udp:close(L) ),
 	    ct:fail({unexpected_closed_info_result, {CC, CE, CS}})
     end,
 
@@ -3214,7 +3220,7 @@ do_simple_sockaddr_send_recv(#{family := _Fam} = SockAddr, _) ->
                       receive
                           {die, Self} ->
                               ?P("[server] terminating"),
-                              (catch gen_udp:close(Sock)),
+                              ?CATCH_AND_IGNORE( gen_udp:close(Sock) ),
                               exit(normal)
                       end
               end,
@@ -3379,8 +3385,8 @@ do_simple_sockaddr_send_recv(#{family := _Fam} = SockAddr, _) ->
     end,
     
     ?P("cleanup"),
-    (catch gen_udp:close(CSock1)),
-    (catch gen_udp:close(CSock2)),
+    ?CATCH_AND_IGNORE( gen_udp:close(CSock1) ),
+    ?CATCH_AND_IGNORE( gen_udp:close(CSock2) ),
 
     ?P("done"),
     ok.
@@ -3416,7 +3422,7 @@ do_kernel_options(Config) ->
             case rpc:call(Node, ?MODULE, do_kernel_options_remote, [Config]) of
                 {ok, Expected} ->
                     ?P("options verified"),
-                    (catch ?STOP_NODE(Node)),
+                    ?CATCH_AND_IGNORE( ?STOP_NODE(Node) ),
                     ok;
                 {ok, [{buffer, ActualBSz},
                       {recbuf, ActualRBSz}] = Actual} 
@@ -3430,12 +3436,12 @@ do_kernel_options(Config) ->
                     ?P("unexpected success:"
                        "~n   Expected: ~p"
                        "~n   Actual:   ~p", [Expected, Actual]),
-                    (catch ?STOP_NODE(Node)),
+                    ?CATCH_AND_IGNORE( ?STOP_NODE(Node) ),
                     exit({unexpected_success, Expected, Actual});
                 {error, Reason} ->
                     ?P("unexpected failure:"
                        "~n   ~p", [Reason]),
-                    (catch ?STOP_NODE(Node)),
+                    ?CATCH_AND_IGNORE( ?STOP_NODE(Node) ),
                     exit({unexpected_failure, Reason})
             end;
         {error, Reason} ->
@@ -3575,7 +3581,7 @@ otp_19332(Config) when is_list(Config) ->
            end,
     Case = fun(State) -> do_otp_19332(State) end,
     Post = fun(#{sock := Sock}) ->
-                   (catch gen_udp:close(Sock))
+                   ?CATCH_AND_IGNORE( gen_udp:close(Sock) )
            end,
     ?TC_TRY(?FUNCTION_NAME, Cond, Pre, Case, Post).
 
@@ -3647,7 +3653,7 @@ do_otp_19357_open_with_ipv6_option(#{local_addr := Addr}) ->
                       try gen_udp:open(0, Opts) of
                           {ok, Sock} ->
                               ?P("success ~w", [No]),
-                              (catch gen_udp:close(Sock));
+                              ?CATCH_AND_IGNORE( gen_udp:close(Sock) );
                           {error, Reason} ->
                               ?P("FAILED open socket ~w: "
                                  "~n   ~p", [No, Reason]),
-- 
2.51.0

openSUSE Build Service is sponsored by