Preventing the document from saving without throwing an error

Hi.

I was wondering if it’s possible to stop a document from saving without using
“frappe.throw()” with the python controllers. The behaviour i’m looking or is exactly like the custom script’s “frappe.validated = false”. However, this doesn’t work in frappe’s python controllers and I have to resort to throwing an error to stop execution.

Is throwing an error (that has to be uncatchable to stop the document from saving) really the only way to stop saving? Throwing an error that prints its entire stack trace in the client’s console surely isn’t good practice?

Would really appreciate some clarification/help.

Thanks! :slight_smile:

Hi @Omar_Alsantali

If you are the one writing the application (not a third party application like frappe)
You can print anything inside frappe.throw("You Message") and hide the error message from the server

But if you want to modify a third party application like (ERPNext or HRMS), you can modify the error message by doing Override

Also if you don’t want to use frappe.throw and prevent saving the document, you can use try and except in Python

Let me know if anything is unclear.