Template PLSQL function with exception

Template of function with description and catching exception into ii_app.p4it_core_logs (in standard ii_app since v.2.56.0).

CREATE OR REPLACE FUNCTION ii_your_schema.f_name_of_function(p_context_input character varying, p_parameter_name character varying)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
        DECLARE
            -- II CORE FUNCTION / 
            -- v1 / DATE / PERSON / Initial version
            -- This function returns XXX
        
         
        
            -- -- -- -- MANDATORY -- -- -- -- 
            var_current_object_name text; 
            var_error_handler text;
            var_error_details text;
            -- -- -- -- -- -- -- -- -- -- -- 

        BEGIN
            var_current_object_name := 'ii_your_schema.f_name_of_function';

            RETURN 'OK';
        
        -- Error handling : catch the error and add the details to the log 
        EXCEPTION WHEN OTHERS THEN
            GET STACKED DIAGNOSTICS var_error_handler = PG_EXCEPTION_CONTEXT;
            
            var_error_details := 
                'Error Name: ' || SQLERRM
                || ' | ----------- | '
                || 'Error State: ' || SQLSTATE
                || ' | ----------- | '
                || 'Error Context: ' || var_error_handler;
                
            PERFORM ii_app.sp_ii_core_log('II Core', 10, var_current_object_name, null, var_error_details);    
            
            RETURN var_result;
        END;
        $function$
;