File 5031-kernel-test-Replaced-use-of-catch-with-try-catch-lib.patch of Package erlang

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

Add catch-and-ignore macro.
Add catch-and-return macro.
Also other replace of catch.
---
 lib/kernel/test/kernel_test_lib.erl | 22 +++++++++++++---------
 lib/kernel/test/kernel_test_lib.hrl |  7 ++++++-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/kernel/test/kernel_test_lib.erl b/lib/kernel/test/kernel_test_lib.erl
index d91a05cc0a..c3235d963f 100644
--- a/lib/kernel/test/kernel_test_lib.erl
+++ b/lib/kernel/test/kernel_test_lib.erl
@@ -555,7 +555,7 @@ analyze_and_print_linux_host_info(Version) ->
     %% 'VirtFactor' will be 0 unless virtual
     VirtFactor = linux_virt_factor(),
     Factor =
-        case (catch linux_which_cpuinfo(Distro)) of
+        try linux_which_cpuinfo(Distro) of
             {ok, {CPU, BogoMIPS}} ->
                 io:format("CPU: "
                           "~n   Model:                 ~s"
@@ -608,6 +608,9 @@ analyze_and_print_linux_host_info(Version) ->
                 num_schedulers_to_factor();
             _ ->
                 5
+	catch
+	    _:_ ->
+		5
         end,
     AddLabelFactor = label2factor(Label),
     %% Check if we need to adjust the factor because of the memory
@@ -2480,7 +2483,7 @@ tc_try(Case, TCCond, Pre, TC, Post)
                             TCRes = TC(State),
                             ?SLEEP(?SECS(1)),
                             tc_print("test case done: try post"),
-                            (catch Post(State)),
+                            ?CATCH_AND_IGNORE( Post(State) ),
                             tc_end("ok"),
                             TCRes
                         end
@@ -2488,7 +2491,7 @@ tc_try(Case, TCCond, Pre, TC, Post)
                         C:{skip, _} = SKIP when (C =:= throw) orelse
                                                 (C =:= exit) ->
                             tc_print("test case (~w) skip: try post", [C]),
-                            (catch Post(State)),
+                            ?CATCH_AND_IGNORE( Post(State) ),
                             tc_end( f("skipping(catched,~w,tc)", [C]) ),
                             SKIP;
                         C:E:S ->
@@ -2500,7 +2503,7 @@ tc_try(Case, TCCond, Pre, TC, Post)
                             case kernel_test_global_sys_monitor:events() of
                                 [] ->
                                     tc_print("test case failed: try post"),
-                                    (catch Post(State)),
+                                    ?CATCH_AND_IGNORE( Post(State) ),
                                     tc_end( f("failed(caught,~w,tc)", [C]) ),
                                     erlang:raise(C, E, S);
                                 SysEvs ->
@@ -2512,7 +2515,7 @@ tc_try(Case, TCCond, Pre, TC, Post)
                                       "~n   E: ~p"
                                       "~n   S: ~p",
                                       [SysEvs, C, E, S]),
-                                    (catch Post(State)),
+                                    ?CATCH_AND_IGNORE( Post(State) ),
                                     tc_end( f("skipping(catched-sysevs,~w,tc)",
                                               [C]) ),
                                     SKIP = {skip,
@@ -2626,11 +2629,12 @@ stop_node(Node) ->
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 timetrap_scale_factor() ->
-    case (catch test_server:timetrap_scale_factor()) of
-        {'EXIT', _} ->
-            1;
+    try test_server:timetrap_scale_factor() of
         N ->
             N
+    catch
+	_:_ ->
+	    1
     end.
 
 
diff --git a/lib/kernel/test/kernel_test_lib.hrl b/lib/kernel/test/kernel_test_lib.hrl
index 1cf21a137e..4dd4b4c362 100644
--- a/lib/kernel/test/kernel_test_lib.hrl
+++ b/lib/kernel/test/kernel_test_lib.hrl
@@ -97,4 +97,9 @@
 -define(SLEEP(T),                ct:sleep(T)).
 -define(TT(T),                   ct:timetrap(T)).
 
+-define(CATCH_AND_IGNORE(_X_),
+	try _X_ catch _:_ -> ignore end).
+-define(CATCH_AND_RETURN(_X_),
+	try _X_ catch __C__:__E__ -> {error, {catched, __C__, __E__}} end).
+
 -endif. % -ifdef(kernel_test_lib_hrl).
-- 
2.51.0

openSUSE Build Service is sponsored by