Home » Scala language

Scala catchAll Object

Scala catchAll object: Scala has a rich set of error handling methods. One of them is the catchAll object, it catches everything. In this tutorial on Scala catchAll object, we will learn about the cattle method was working examples.
Submitted by Shivang Yadav, on August 09, 2019

Scala being a scalable programming language has good support for all types of things. In exception handling also scala has many methods defined to do advanced things in error handling.

One of advanced method that is supported by Scala is the catchAll object.

The catchAll object is the object that can catch all types of exceptions in the program. This object is used when we do not know what type of exception will be thrown.

Syntax to define the working of Scala catchAll object:

    allCatch.opt(1.toInt)
    res10: Option[Int] = Some(1)

The below is a code snippet that will help you learn this concept more clearly,

    scala> allCatch.opt(1.toInt)
    res10: Option[Int] = Some(1)
    scala> allCatch.opt("a".toInt)
    res11: Option[Int] = None

This code is used to reduce errors while working with integer value comparisons. If the value is integer it will return an integer and if any other value is entered say character, then it will return the NULL values.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.