Jon,

The Redpaper was published in 2007.

I was under the impression the redpaper was more up to date than the
original copy of the redbook; which was published in 2000.

But the link I provided is the newer version of the redbook published in
2016. Which seems to include everything in the redpaper.

Am I missing something?

Charles


On Thu, Jan 7, 2021 at 8:28 AM Jon Paris <jon.paris@xxxxxxxxxxxxxx> wrote:

There's actually a redpaper that is more complete on the subject Charles -
it was written as a follow-up to the redbook. Admittedly neither include
ON-EXIT since that is such a recent addition.

https://www.redbooks.ibm.com/redpapers/pdfs/redp4321.pdf?q=error-handling
<https://www.redbooks.ibm.com/redpapers/pdfs/redp4321.pdf?q=error-handling






On Jan 7, 2021, at 9:24 AM, Charles Wilt <charles.wilt@xxxxxxxxx> wrote:

I'd suggest reading through Chapter 7 - Exception and error handling of
the
"Who Knew You Could Do That with RPG IV? Modern RPG for the Modern
Programmer" Redbook.

https://www.redbooks.ibm.com/abstracts/sg245402.html?Open

Charles


On Thu, Jan 7, 2021 at 6:26 AM Kris Chantry <kris.chantry@xxxxxxxxx>
wrote:



Hello,



I wonder if there is an easy way to know what the ERROR was, which
caused a
program to END ABNORMALLY?



I want to create a generic ERROR HANDLING procedure by which I can
inform
everybody in the IT deparment about a problem that occurred 1 or
multiple
times.

I would like to use the ON-EXIT function to accomplish this.

So when the ON-EXIT tells me that there was an error, I want to store
the
Error Message Data in a DB File and send (periodicly) emails to the IT
Department about the errors that occurred and according the severity of
the
error.



Can somebody tell me how I can retrieve the error message in the
ON-EXIT?



Please find a simple example program about how I would like to structure
this.



Kind regards,

Kris





**FREE




//**************************************************************************
******************

// PROGRAM : Automatic Error Handling TEST

//


----------------------------------------------------------------------------
---------------

// DATE DESCRIPTION
USER TICKETNR

//


----------------------------------------------------------------------------
---------------

// 09/12/20 Creation of the program
JOHN DOE

// ../../.. .......................
.......... ../.....




//**************************************************************************
******************

//---- H-Specs ----

ctl-opt main(main_Procedure);

ctl-opt option(*srcstmt: *nodebugio: *nounref);

ctl-opt datedit(*DMY/);

ctl-opt decedit('0,');

ctl-opt alwnull(*usrctl);

ctl-opt datfmt(*ISO);

ctl-opt timfmt(*ISO);



//--- D(descriptive)-Specs ---

/include QPROTOTYPE,ERRREPORT



dcl-s v_lib char(10) inz('');

dcl-s MyFile char(10) inz('CUSTOMER');

dcl-ds MyFileQual Qualified;

File char(10);

Lib char(10);

end-ds;



dcl-s i_errorOccured ind inz(*off);



//--- ERROR HANDLING datastructure ---

dcl-ds errorHandlingDS;

e_environment char(10); //In which environment did the
error
occur

e_program char(30); //In which program did the
error
occur

e_library char(10); //In which library did the
error
occur

e_module char(10); //In which module did the
error
occur

e_procedure char(128); //In which procedure did the
error
occur

e_statement packed(7:0); //At which statement dit the
error
occur

e_callerPgm char(10); //What was the caller program

e_callerUser char(10); //Who activated the program

e_errorID char(20); //What was the error ID
(MCH....)

e_errorSeverity packed(2:0); //What was the error Severity

e_errorType char(20); //What was the error Type
(diagnostic/Escape/...)

e_errorTitle char(128); //What was the error Title

e_errorMessage char(25000); //What was the error Message

e_errorCause char(25000); //What was the error Cause

end-ds;



//--- Program datastructure ---

DCL-DS *n PSDS;

@pgmname char(10) pos(1);

@status *STATUS;

@routine *ROUTINE;

@exceptType char(4) pos(40);

@exceptNr char(3) pos(43);

@pgmLibrary char(10) pos(81);

@exceptData char(80) pos(91);

@job char(10) pos(244);

@user char(10) pos(254);

@jobnr zoned(6 : 0) pos(264);

@srcFile char(10) pos(304);

@srcLibrary char(10) pos(314);

@srcMember char(10) pos(324);

@srcProgram char(10) pos(334);

@srcModule char(10) pos(344);

@jobId char(16) pos(380);

@systemName char(8) pos(396);

END-DS;






//**************************************************************************
*****************

// B E G I N N I N G O F T H E P R O G R A M




//**************************************************************************
*****************

dcl-proc main_Procedure;

dcl-s v_value1 packed(5:0) inz(0);

dcl-s v_value2 packed(5:0) inz(0);

dcl-s v_value3 packed(5:0) inz(0);



clear errorHandlingDS;

e_program = @pgmname;

e_procedure = %proc();



//--- No problem / returnValue = 20 ---

v_value1 = 10;

v_value2 = 10;

v_value3 = makeCalculation(v_value1:v_value2:'+');

//--- MCH1210 (severity 40)

//--- Receiver value too small to hold result ---

v_value1 = 100;

v_value2 = 99999;

//v_value3 = makeCalculation(v_value1:v_value2:'+');





//--- No problem / returnValue = 90 ---

v_value1 = 100;

v_value2 = 10;

v_value3 = makeCalculation(v_value1:v_value2:'-');

//--- No problem / returnValue = -90 ---

v_value1 = 10;

v_value2 = 100;

v_value3 = makeCalculation(v_value1:v_value2:'-');

//--- MCH1210 (severity 40)

//--- Receiver value too small to hold result ---

//v_value3 = (10 - 9999999999);





//--- No problem / returnValue = 100 ---

v_value1 = 10;

v_value2 = 10;

v_value3 = makeCalculation(v_value1:v_value2:'*');

//--- MCH1210 (severity 40)

//--- Receiver value too small to hold result ---

v_value1 = 100;

v_value2 = 99999;

//v_value3 = makeCalculation(v_value1:v_value2:'*');





//--- No problem / returnValue = 10 ---

v_value1 = 100;

v_value2 = 10;

v_value3 = makeCalculation(v_value1:v_value2:'/');

//--- No problem / returnValue = 0 (no comma)---

v_value1 = 10;

v_value2 = 100;

v_value3 = makeCalculation(v_value1:v_value2:'/');



//--- MCH1211 (severity 40)

//--- Attempt made to divide by zero for fixed point operation. ---

v_value1 = 100;

v_value2 = 0;

v_value3 = makeCalculation(v_value1:v_value2:'/');



on-exit i_errorOccured;

if i_errorOccured;

// here I want to know:

// -------------------

// WHICH problem occured (Divide by zero, too small, ...)

// WHICH Error type (escape, ...)

// WHICH severity

// In which procedure it happened

// At which statement

// ...

reportProblem(e_procedure);

endif;



*inlr = *on;

return;

end-proc;






//--------------------------------------------------------------------------
-----------------

// Make a calculation




//--------------------------------------------------------------------------
-----------------

dcl-proc makeCalculation;

dcl-pi makeCalculation packed(5:0);

p_value1 packed(5:0) const;

p_value2 packed(5:0) const;

p_type varchar(1) const;

end-pi;



dcl-s v_returnValue packed(5:0) inz(0);



e_procedure = %proc();



clear v_returnValue;

select;

when (p_type = '+');

v_returnValue = p_value1 + p_value2;

when (p_type = '-');

v_returnValue = p_value1 - p_value2;

when (p_type = '*');

v_returnValue = p_value1 * p_value2;

when (p_type = '/');

v_returnValue = p_value1 / p_value2;

endsl;



return v_returnValue;



end-proc;






//--------------------------------------------------------------------------
-----------------

// Report the problem to the Developers




//--------------------------------------------------------------------------
-----------------

dcl-proc reportProblem;

dcl-pi reportProblem;

p_procedure char(128);

end-pi;



e_program = @pgmname;

e_procedure = %trim(p_procedure);

e_errorTitle = 'SomeThing happened!!';



//Send an email or submit the error data to a file...

saveErrorReport(errorHandlingDS);



end-proc;







--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription
related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.