Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle exception in Julia

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.

like image 605
Yago Azedias Avatar asked Jan 23 '18 18:01

Yago Azedias


1 Answers

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.

like image 51
Bogumił Kamiński Avatar answered Oct 01 '22 21:10

Bogumił Kamiński