Reputation: 4868
I want to handle a exception in Julia Lang, just like I did with Javascript:
try {
} catch(e) {
console.log("Exception: " + e);
}
I read the documentation but I'm not able to understand.
Upvotes: 8
Views: 6223
Reputation: 69839
The equivalent to your code is:
try
sqrt(-1) # Code that may throw an exception.
catch y
warn("Exception: ", y) # What to do on error.
end
The full structure of try
/catch
statement is:
try
# Code that may throw an error.
[catch [identifier]
# What to do if exception is raised.
]
[finally
# What to do unconditionally when try/catch block exits.
]
end
Parts in square brackets are optional. In particular if you want to omit identifier
you should use a newline or ;
after catch
.
Upvotes: 17