fireproofsocks
Raising a custom exception: module not available?
I can’t seem to make custom exceptions work. If I define a module like this:
defmodule MyApp.CustomException do
defexception message: "Something bad happened."
end
then somewhere else in my app I reference it:
defmodule Something do
alias MyApp.CustomException
def do_something(nil) do
raise CustomException
end
end
I get this error:
function MyApp.CustomException.exception/1 is undefined (module MyApp.CustomException is not available)
What am I missing? I thought I was following https://elixir-lang.org/getting-started/try-catch-and-rescue.html correctly…
Marked As Solved
fireproofsocks
FOUND IT. I accidentally put my module outside of lib/. Whoops.
2
Also Liked
blatyo
Conduit Core Team
When I get this it’s usually a spelling issue for the module name.
1
NobbZ
Your example works for me:
Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule MyApp.CustomException do
...(1)> defexception message: "Something bad happened."
...(1)> end
iex(2)> defmodule Something do
...(2)> alias MyApp.CustomException
...(2)>
...(2)> def do_something(nil) do
...(2)> raise CustomException
...(2)> end
...(2)> end
iex(3)> Something.do_something(nil)
** (MyApp.CustomException) Something bad happened.
iex:6: Something.do_something/1
1
Popular in Questions
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Other popular topics
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New







