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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.