119
Views
4
Comments
Solved
How to best handle SQL error messages.
Question
Application Type
Reactive

Hi All ,

What is the best way to handle error messages thrown from SQL queries  in a server action?


Regards,

 Ishmael

2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi Thizwilondi,


Use the DatabaseException to capture an exception occurred in the query. You just need to drag the ExceptionHandler from the left pane, and select the DatabaseException type.



As shown on the message, you will have access to the database exception message with DatabaseException.ExceptionMessage, and you can set up your own logic to deal with it.


You can read more in OutSystems documentation about handling exceptions, and database exceptions in particular.


Kind Regards,
João

UserImage.jpg
Ishmael

Hi João,

Thank you for the respond , does that database exception encapsulate the message to avoid giving much information about the tables ?  Given that I do not give it a custom error message.

2018-10-29 08-31-03
João Marques
 
MVP

That's the part of handling it :)

If you just want to avoid disclaiming your internal tables (which is a good practice by the way), you can raise an exception with your custom message, like on the image below:



Cheers,
João

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.