How to intercept error from sc_exec_sql

I am using sc_exec_sql in a button event.

Sometimes I get an error from the database which SC automatically displays in the browser.

I would like to intercept the error and manage it programmatically rather than having it displayed automatically by SC.

Is there a macro to intercept an SQL error ?

I know about sc_error_insert/update/delete but such macro works only on the OnInsert/OnUpdate/OnDelete event chain and not on other generic event.

Thanks for your help.

You can use sc_select() to replace sc_exec_sql and intercept the error there.

You can find a short blog how to this at:

Or define a function in an internal library and use it instead of sc_exec_sql():

function asdw_exec_sql($befehl)
	{	// Verbessertes sc_select mit Fehlerbehandlung
	
		sc_select(asdw_my_data,$befehl);
		if ({asdw_my_data} === false)
			{
                            // Your error handler liek:
				die ({asdw_my_data_erro}. " from SQL: " . $befehl);
			}
		else
			{
				return({asdw_my_data});
			}
	}

Hope this will help!

Best regards
Gunter Eibl

Thanks a lot.
It works perfectly.