Throwing exceptions

A Scala method can throw an exception because of the unexpected workflow. You create an exception object and then you throw it with the throw keyword as follows. For example:

//code something
throw new IllegalArgumentException("arg 2 was wrong...");
//nothing will be executed from here.

Note that the primary goal of using exception handling is not to produce friendly messages but to exit the normal flow of your Scala program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.234