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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With