‎2007 Mar 12 8:57 AM
hi,
What is the difference between CATCH and RAISE exeptions.
I have a structure 's_struc' and in that structure i have a table type 't_table'.
Now i have to move fields into that table type from my internal table itab1.
will the following code help
try.
s_struc = itab1.
raise exception type cx_hrpa_invalid_parameter
exporting
parameter = l_parameter1
value = l_value1.
endtry.
will this code be feasible.
How will the above code behave if i write catch?
pls help.
Deepak
‎2007 Mar 12 9:29 AM
Hello Deepak
Your coding will result a syntax-error and, thus, cannot be executed. Assuming that the table type field within your structure has the name ITAB then you need to code:
TRY.
s_struc-itab = itab1.
...
ENDTRY.If you do not catch the exception within your TRY - ENDTRY block then the system checks whether somewhere "upsteam" there is a CATCH block. If no CATCH block is found then nothing should happen and the flow continues after the ENDTRY statement.
CATCH statement: event handling of a raised exception
Regards
Uwe
‎2007 Mar 12 9:29 AM
Hello Deepak
Your coding will result a syntax-error and, thus, cannot be executed. Assuming that the table type field within your structure has the name ITAB then you need to code:
TRY.
s_struc-itab = itab1.
...
ENDTRY.If you do not catch the exception within your TRY - ENDTRY block then the system checks whether somewhere "upsteam" there is a CATCH block. If no CATCH block is found then nothing should happen and the flow continues after the ENDTRY statement.
CATCH statement: event handling of a raised exception
Regards
Uwe
‎2007 Mar 12 9:44 AM
Ok Uwe
i am getting your point.
My requirement is i need to update the fields of internal table into the table type t_table which is in structure t_struc. If any field mismatch then it should throw an exception cx_hrpa_invalid_parameter setting parameter and value attributes to my local variables l_parameter1 and l_value1.
and by your suggestion i modified the code to the following :
TRY.
s_struc-t_table = itab1.
CATCH cx_hrpa_invalid_parameter INTO oref
l_parameter1 = oref->parameter.
l_value1 = oref->value.
ENDTRY.
is the above code correct?
Deepak
‎2007 Mar 12 10:57 AM
Hello Deepak
Depending on whether your report has the flag <b>"Unicode-enabled"</b> set or not you will get a different result of the syntax check (SLIN) for statement
s_struc-t_table = itab1.<b>- Unicode-enabled = 'X':</b> => syntax error if the structures do not match exactly
<b>- Unicode-enabled = ' ': </b>=> perhaps no syntax error but system-exceptions due to type conversion errors possible
In the latter case you would use the following statement:
CATCH SYSTEM-EXCEPTIONS <type conversion error> = 1.
s_struc-t_table = itab1.
...
ENDCATCH.However, please note that the CATCH SYSTEM-EXCEPTIONS is different from class-based exception handling because this statement does not return any error object.
Regards
Uwe
‎2007 Mar 12 11:56 PM
RAISE-->For raising the exception/event.
CATCH->For catching the exception.
Cheers,
Hakim
‎2007 Mar 14 10:27 AM
hi,
first of all if you use a raise statement in a try-endtry block and dont catch it, there is no point in using this try endtry block.
try -endtry block for used if there are chances of some runtime errors and you use catch statement to deal with those errors(exceptions). If you dont use catch statement then the normal flow of program will continue. and the program will dump if some exception is occured in some statement in try-endtryblock.
Hope this explaination helps.
Regards,
Richa