PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 5, 2022

[FIXED] How to add texts messages to exceptions defined by local classes?

 August 05, 2022     abap, class, exception, local     No comments   

Issue

I want to raise an exception of a local type, and pass it in the constructor a *text.

This *text is what i want to be returned by calling the get_longtext method, later, when i catch the exception.

Of course i can add an attribute to my class, and redefine the method. It seems to me like there should however be an easier way (like there is in the java-like languages, where you just "have" that).

There's the TEXTID parameter in the inherited constructor for the exceptions. That however points to the "texts" defined as class properties... but that's for global classes.

So is there any way for me to make use of the already existing constructor in an elegant way? Or must I simply do it all by hand?


Solution

If you don't want to uses global classes (as recommended), you can try to implement the interface IF_T100_MESSAGE in your local class. First maintain the error messages in any message class via SE91, then define text ids in your local exception class of type SCX_T100KEY. Implement the exception class methods to use additional attributes for the placeholders in your message texts (if necessary).

Check IF_T100_MESSAGE and CL_MESSAGE_HELPER for details. To get example code, create a global exception class and add the interface IF_T100_MESSAGE and check how the methods are implemented.



Answered By - Hans Hohenfeld
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing