Creating Exception Classes using Code Templates
Maybe you already asked yourself how to create an exception class with the ABAP development tools in eclipse without having the exception builder for generating the exception IDs. In this blog you will see how the code templates in eclipse become your friend:
Creating an exception class in eclipse is done via the class creation wizard (CTRL+N) just by adding an already existing exception class as the superclass:
The tool creates the new class in the repository and automatically generates the constructor into the source code. The newly created class will be opened in as a new editor tab in eclipse.
Now you want to add an exception ID to the class in order to assign a message to your excption class.
For that the IDE provides you with an ABAP specific code template that you find in the eclipse template gallery (Menu Window->ShowView->Templates)
You can pick this template in the source code editor just by typing the name of the template and using the code completion:
The preview in the yellow box beside the template gives you a hint what happens when you choose the template.
After choosing the template via pressing ENTER the editor generates the code of the exception ID into your exception class.
Now you can enter the message class ID and message number of your choice. Ideally you open the message class in the eclipse-based message class editor for your convenience:
Have fun.
Regards,
Thomas.
Good tips, simple tricks - thank you 🙂
hi Thomas,
thanks for another good eclipse how to!
Somehow it's much more fun to use template in eclipse than in SE80. Comes more naturally and is much better integrated in the flow of work. I think there might still be lot of potential for further use cases...
Viele Grüße
Hendrik
Hi Thomas,
usually when working with exception classes i use OTR-based text elements. Is there any way to edit these text elements via eclipse as well. Currently my workflow involves switching to the SAP GUI in order to create the necessary texts.
Christian
Hi Christian,
currently there is no possibility in eclipse to maintain the OTR Texts of an exception class. Our recommenadation is to use message-class based exception classes so the support for OTR texts has not the highest prio for us. But I see a chance to provide this as the Web Dynpro Tools also using OTR texts and they have already a solution in eclipse. Hope we can reuse parts of it.
Regards,
Thomas.
Hey Thomas Fiedler
I also prefer not to use message based exceptions.
What's the status to this topic 10 years later? 😎
Cheers
~ Enno
Hi Enno,
the status is unchanged. OTR and OTR-based exception classes are not in focus anymore. So there will be no support in ADT for that. You have to use SE24 to edit OTR based exception classes.
Regards,
Thomas.
It's a pity, but thanks for clarification!
May be I should then overhink my approach of not using message exception classes...
There is also a sentence about it in the ABAP Docu:
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexception_texts_guidl.htm
Regards,
Thomas.