1818import io .serverlessworkflow .fluent .func .spi .ConditionalTaskBuilder ;
1919import io .serverlessworkflow .fluent .func .spi .FuncTaskTransformations ;
2020import io .serverlessworkflow .fluent .spec .BaseTryTaskBuilder ;
21+ import java .util .function .Consumer ;
2122
2223public class FuncTryTaskBuilder
2324 extends BaseTryTaskBuilder <FuncTryTaskBuilder , FuncTaskItemListBuilder >
@@ -32,4 +33,54 @@ public class FuncTryTaskBuilder
3233 protected FuncTryTaskBuilder self () {
3334 return this ;
3435 }
36+
37+ /**
38+ * Defines the tasks to execute within the try.
39+ *
40+ * @param tryHandler a consumer that configures the tasks to be executed in the try
41+ * @return this builder instance for method chaining
42+ */
43+ public FuncTryTaskBuilder tryCatch (Consumer <FuncTaskItemListBuilder > tryHandler ) {
44+ return this .tryHandler (tryHandler );
45+ }
46+
47+ /**
48+ * Defines a catch that handles specific errors and executes tasks when those errors occur.
49+ *
50+ * @param catchErrors a consumer that configures which errors to catch (e.g., by type, status
51+ * code)
52+ * @param catchHandler a consumer that configures the tasks to execute when the specified errors
53+ * are caught
54+ * @return this builder instance for method chaining
55+ */
56+ public FuncTryTaskBuilder catchError (
57+ Consumer <CatchErrorsBuilder > catchErrors , Consumer <FuncTaskItemListBuilder > catchHandler ) {
58+ return this .catchHandler (handler -> handler .errorsWith (catchErrors ).doTasks (catchHandler ));
59+ }
60+
61+ /**
62+ * Defines a conditional catch that executes tasks when a specific condition is met.
63+ *
64+ * @param expr a runtime expression that evaluates to a boolean, determining whether to execute
65+ * the catch handler
66+ * @param catchHandler a consumer that configures the tasks to execute when the condition
67+ * evaluates to true
68+ * @return this builder instance for method chaining
69+ */
70+ public FuncTryTaskBuilder catchWhen (String expr , Consumer <FuncTaskItemListBuilder > catchHandler ) {
71+ return this .catchHandler (handler -> handler .when (expr ).doTasks (catchHandler ));
72+ }
73+
74+ /**
75+ * Defines a catch that handles errors of a specific type.
76+ *
77+ * @param type the error type to catch (e.g., "java.lang.NullPointerException")
78+ * @param catchHandler a consumer that configures the tasks to execute when an error of the
79+ * specified type is caught
80+ * @return this builder instance for method chaining
81+ */
82+ public FuncTryTaskBuilder catchType (String type , Consumer <FuncTaskItemListBuilder > catchHandler ) {
83+ return this .catchHandler (
84+ handler -> handler .errorsWith (err -> err .type (type )).doTasks (catchHandler ));
85+ }
3586}
0 commit comments