Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Explain exception handling in scala?



Explain exception handling in scala?..

Answer / Rakesh Kumar Lohani

Exception handling in Scala is done using the Try and Throw exceptions. The Try class provides a way to evaluate expressions that might throw an exception, and it returns a Try object containing either the result or the exception. You can use the methods isSuccess(), isFailure(), get(), and recover() on a Try object to handle exceptions. For example:nn```scalanval result = Try { // Evaluate expression that might throw an exceptionn val x = 1 / 0n} // Try object creatednif (result.isFailure) {n println(s"An error occurred: ${result.failed.getMessage}")n}nelse {n println(s"Result: $result")n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

What are the Advantages of Functional Programming (FP) or Advantages of Pure Functions?

1 Answers  


Is Scala Statically-Typed Language?

1 Answers  


Does a Companion object access private members of it’s Companion class in Scala?

1 Answers  


What is flatmap in scala?

1 Answers  


Explain different types of identifiers in scala?

1 Answers  


How do we declare a private Primary Constructor in Scala? How do we make a call to a private Primary Constructor in Scala?

1 Answers  


What is a nexted function in scala?

1 Answers  


What do you understand by apply and unapply methods in scala?

1 Answers  


Give some examples of packages in scala?

1 Answers  


What is the difference between Function and Method in Scala?

1 Answers  


What’s performing currying in Scala?

1 Answers  


What is function composition in scala?

1 Answers  


Categories