Learn how to gracefully handle exceptions in Scala. Scala provides the same type of exception handling as Java or C++, you can throw an error. The program will check for code to 'handle' the error, but if none exists, it will exit the program.
- [Narrator] It's important to understand what happens…when your program has an error.…Maybe a logic error.…Scala provides the same type of exception handling…as you'll see in java and C++…and we can even throw our own errors.…Let's take a look at a sample program that has an error.…In your exercise files folder under O three O three,…you'll find an error handling template.…It only has this basic code that you see here.…So let's start by adding a library…that will allow us to read from a file.…So we're going to go up to the top here,…and we're going to import io.Source…and because I just want to allow it to read…all the methods within this class…I'm just going to do dot underscore, which is our wild card.…
In the main part of the program,…I'm going to keep it real simple and I'm just going to use…a for loop to print out all the values…inside of a file that doesn't exist.…So we'll start with a for, and we're going to give it a name.…We'll say line and that represents each line of values…in our file, and we're going to say from file,…
Join Peggy Fisher as she helps get you started with Scala, so you can leverage the unique capabilities it offers. First, learn the basics of type inference, variables, loops, functions, and operators. Then, find out how to read files using a console, perform pattern matching, handle exceptions, and more. Finally, learn how to use classes, fields, methods, and objects.
- Integrating with IDEs
- Scala worksheets
- Scala repl sessions
- Type inference
- Creating variables
- Working with loops
- Higher-order functions
- Scala operators
- Working with decision statements
- Handling exceptions using try or catch
- Working with tuples and arrays
- Classes, fields, and methods
Skill Level Intermediate
Java Platforms Compared: SE vs EE vs MEwith Peggy Fisher25m 38s Intermediate
Scala Essential Training for Data Sciencewith Dan Sullivan1h 51m Intermediate
1. Getting Started with Scala
2. Scala Basics
3. More Scala Basics
4. Objects with Scala
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.