The question you’re directly asking here has been thoroughly answered, and in fact it’s explicitly covered in Elixir docs, so you might want to give that whole section a read: Design-related anti-patterns — Elixir v1.20.2 (although personally I find that some of those issues are more stylistic decisions that come with tradeoffs than “genuine” anti-patterns).
But to go a bit further, since it sounds like you are new to the library… if you are getting exceptions from Ecto something may have already gone wrong. As you can see from the docs, most Ecto operations do not raise errors by default, instead they return error tuples already so there is no exception to let bubble up or not, and you have to use a separate ! version of the function to get it to raise, so you may want to check you are using the right API for your case. The operations that do raise errors “unexpectedly” mostly do so because the inputs are invalid (for example if you pass in value with a data type that doesn’t match the db field). In those cases you are missing some sort of validation higher up the call chain. If you want to provide more context about where you are running into this issue, we might be able to offer more specific advice.


















