Understanding Exceptions with login

hey guys,
Does anyone know how does the exceptions raised in the login.py / auth.py work ?
I need to raise an exception before the login happens, and on some condition, prevent the login .
I used this call in a whitelisted python func

frappe.throw(_("Message"), frappe.AuthenticationError)

But this doesn’t seem to work. I also tried sys.exit() and raise SystemExit but with no success. They just raise the exception and print the traceback in the console.

Any suggestions ?

@Akarsh_Hegde depends on what context you are using.

Do you have some code to share?

I was trying to include an authentication based on otp , so wanted to modify the login process. Anyways, The same throw works only in auth.py file. Managed to change the logic and get it working. Thank you!