Please see my comment to the question. I cannot understand what you mean and not sure that you understand what you want to achieve, sorry.
Anyway, exception handling is the feature of Transact-SQL, which is the extension to SQL, so you may want to start here:
TRY...CATCH (Transact-SQL),
Transact-SQL.
However, mostly likely, you need to understand how exception handling works, which is not a trivial topic, despite the fact that nearly everyone uses exception handling. I tried to explain just the general idea in my past answers:
Does Exception in C# Constructor Cause Caller Assignment to Fail?,
where was stored .net exceptions in operating system.
The topic is quite fundamental and serious, takes real education; my answered can be considered as just the hint, at best.
—SA