CUSTOM ERROR MESSAGES.

CUSTOM ERROR MESSAGES.

  
HOW DO I CREATE CUSTOM ERROR MESSAGES FOR DATABASE exceptions?
 
Example: INSTEAD OF THIS MESSAGE: "The DELETE statement conflicted with the REFERENCE constraint" OSFRK_OSUSR_q2t_Torres_OSUSR_Q2T_FASE_IDFASE. "The conflict occurred in database" outsystems__ "table" dbo.OSUSR_Q2T_TORRES ", column 'IDFASE.' Has Been The statement terminated.". A MESSAGE APPEARS more friendly.
Catch the exception with an Exception Handler, and in the logic from there, do what you think would be better.

This is a prime example of where the "default logic" isn't the "best logic". Dumping system exceptions to FeedbackMessage is a REALLY bad way of doing things, but lots of people think that this is the "right" way because Intelliwarp does it like this...

J.Ja
Comparing strings, which I have done to overcome Paulo's dilema seems even worse to me but it's the only option I have...
Justin James wrote:
Catch the exception with an Exception Handler, and in the logic from there, do what you think would be better.

This is a prime example of where the "default logic" isn't the "best logic". Dumping system exceptions to FeedbackMessage is a REALLY bad way of doing things, but lots of people think that this is the "right" way because Intelliwarp does it like this...

J.Ja
 
 But I would like to specifically customize this message. Other messages may be the pattern. It has several execessoes database, we can choose one and customize it?
Hi Paulo,

Instead of trying to customize a database exceptions, isn't it possible for you to check if the database operations should be possible first?

I undestand that letting the database engine to calculate constaints is easyer for you.
In in practice depending on the data you should either have "Delete" rules instead of "Protect" in your entities references or protect the the application code to check if a delete is possible first.

Following your example: If you are trying to delete a FASE, then before deleting do a simple query to if there are any TORRES using that fase and display a specific message.

Anyway, to answer your question. The messages come directly from the database, so you cannot customize them.
You can, like Joao Heleno said, on your error handlers parse the exception message and display a different message. But it is very error prone and usually causes more problems than what it tries to solve.

Regards,
João Rosado
Do not make sense then put the rule of protection. Users will not like to see message complex. Instead we could view messages friendly. Ex: exclusion not allowed! The stage that you want to delete it belongs ...