How can I know if I'm run of limits?

The question

I want to know if I’m run out of d1 row read, KV read limits.

Some explanations for my question

I know worker AI will return error according to the document, But how can I get the error code if error occur?
Will d1 or kv also give similar error? or how can I know if my calling process is failed due to I’m running out of the usage limit?