06-29-2012 9:00 AM
Hi,
in SE24, tab "local types", the comment given by SAP says:
*"* use this source file for any type declarations (class
*"* definitions, interfaces or data types) you need for method
*"* implementation or private method's signature
Now I've defined a local exception class in this tab:
CLASS lcx_my_exception DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
So far no error occurs.
But when trying to use it in the signature of a private! class, it is not known and I'm asked wether I like to create it as a global exception class.
Why isn't the exception class recognized?
My mistake or a bug?
Regards,
Dirk
10-22-2012 8:44 AM
Hello Dirk,
i cant follow that problem.
I tried the following:
*"* use this source file for any type declarations (class
*"* definitions, interfaces or data types) you need for method
*"* implementation or private method's signature
CLASS lcl_cx DEFINITION INHERITING FROM cx_static_check.
ENDCLASS. "lcl_cx DEFINITION
METHOD i_raise_it.
RAISE lcl_cx.
ENDMETHOD.
No error occurs.
Even if I make the method public, it works.
I did this in ECC 6.0.
Maybe this works not until a special version?
Regards,
Stefan Wolf
07-05-2012 8:37 AM
Your mistake. Class based exceptions for methods must be globally defined exceptions. It'd be kind of nice if you could use private ones though.
07-05-2012 9:15 AM
Yes, it would be nice.
If the method is private it's called only inside the class. Why have exceptions thrown by this method be known outside? It's inconsistent in my optionion.
Regards,
Dirk
10-22-2012 8:44 AM
Hello Dirk,
i cant follow that problem.
I tried the following:
*"* use this source file for any type declarations (class
*"* definitions, interfaces or data types) you need for method
*"* implementation or private method's signature
CLASS lcl_cx DEFINITION INHERITING FROM cx_static_check.
ENDCLASS. "lcl_cx DEFINITION
METHOD i_raise_it.
RAISE lcl_cx.
ENDMETHOD.
No error occurs.
Even if I make the method public, it works.
I did this in ECC 6.0.
Maybe this works not until a special version?
Regards,
Stefan Wolf
10-24-2012 8:05 AM
Hello Dirk,
did you solve the problem?
Could you share the crux of the matter with us?
Regards,
Stefan Wolf
10-24-2012 8:38 PM
Hi Stefan,
sorry not yet, but I will keep you informed.
Currently there's not much time for experiments .
Regards,
Dirk
10-24-2012 8:44 PM
04-22-2013 2:44 AM
Hi Dirk,
I've been trough the same issue and "solved" it by declaring the super class (CX_DYNAMIC_CHECK in my case) in the signature of my private method.
Works fine for me.
Cheers,
Custodio
04-22-2013 12:11 PM
Hi Custodio,
thanks for your reply.
I tested your solution and it worked. It's a possible workaround of course but it makes the code a bit "unclear" beause you can't see in the signature which exception can actually be thrown.
Regards,
Dirk
02-04-2021 4:55 AM
I use eclipse to write this:
In the sample class below, I use a private method to process Fibonacci number called in the public class " get_fib".
hope this answers your question.
In the LOCAL TYPES
*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
CLASS lcx_input IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
m_message = i_message.
ENDMETHOD.
METHOD get_message.
r_message = m_message.
ENDMETHOD.
ENDCLASS.
In the CLASS-RELEVANT LOCAL TYPES
*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
CLASS lcx_input DEFINITION
INHERITING FROM cx_static_check FINAL.
PUBLIC SECTION.
METHODS: constructor IMPORTING i_message TYPE string,
get_message RETURNING VALUE(r_message) TYPE string.
PRIVATE SECTION.
DATA: m_message TYPE string.
ENDCLASS.
In the GLOBAL CLASS
CLASS ycl_fibonacci_number DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
METHODS get_fib IMPORTING i_index TYPE i
RETURNING VALUE(r_fib_number) TYPE i
RAISING /iwbep/cx_mgw_busi_exception.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS process_fib IMPORTING i_index TYPE i
RETURNING VALUE(r_fib_number) TYPE i
RAISING lcx_input.
ENDCLASS.
CLASS ycl_fibonacci_number IMPLEMENTATION.
METHOD get_fib.
TRY.
r_fib_number = process_fib( i_index ).
CATCH lcx_input INTO DATA(input_ex).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited
message_unlimited = input_ex->get_message( ).
ENDTRY.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
ENDMETHOD.
METHOD process_fib.
IF i_index < 0.
RAISE EXCEPTION TYPE lcx_input
EXPORTING
i_message = 'Input can not be less than zero'.
ENDIF.
IF i_index = 0.
r_fib_number = 0.
ELSEIF i_index = 1.
r_fib_number = 1.
ELSE.
r_fib_number = process_fib( i_index - 1 ) + process_fib( i_index - 2 ).
ENDIF.
ENDMETHOD.
ENDCLASS.