How to raise exception?

The problem I’m having

In Oracle, we used to use RAISE_APPLICATION_ERROR to raise exceptions and terminate the execution of the program immediately. What could be the way here?

The context of why I’m trying to do this

I have written a macro which has 100 lines of code; In middle of code; based on some condition, I want to raise the error and terminate the code immediately.

What I’ve already tried

I have done logging of the error and used IF/ELSE to process. But this will not fail the program or raise the error. I checked exceptions | dbt Developer Hub ; But this show “raise_compiler_error” and not the exception which might occur during execution.

Some example code or error messages

Hi Ashish!

I would recommend consulting the docs for this sort of question. I searched ‘exception’ and the first result was this: https://docs.getdbt.com/reference/dbt-jinja-functions/exceptions

Note: @Josh Devlin (he) originally posted this reply in Slack. It might not have transferred perfectly.

Can you provide the code that you’re running which isn’t raising an exception? As Josh noted, the exceptions object that you found should behave the way you’re hoping.

Or have you not tried it because it calls itself a compiler error instead of a runtime error? dbt will compile your code (including running any introspective queries) before running it, which means that a compiler error is correct.

If you provide more details about this

then it might be possible to help further

A post was split to a new topic: Does dbt have exception handling for DML/DDL code?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.