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

Explain operator and Explain types of operators in scala?

1 Answers  


What is the advantage of Scala?

1 Answers  


Give some examples of packages in scala?

1 Answers  


What is the Main drawback of Scala Language?

1 Answers  


Why scala is faster than java?

1 Answers  


What is scala and why it is used?

1 Answers  


What is file handling in scala?

1 Answers  


What are the Scala variables?

1 Answers  


What is a higher-order function in scala?

1 Answers  


What is the difference between apply and unapply methods in scala?

1 Answers  


What is function composition in scala?

1 Answers  


What is a function literal in scala?

1 Answers  


Categories