Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Scala Online

import scala.util.matching._
class TypeException(s:String) extends Exception(s){
}


object HelloWorld {
    @throws(classOf[TypeException]) 
   def checkType(input:String) =
   {
    val integerPattern  =raw"([0-9]+)".r
    val stringPattern =raw"([a-zA-Z\s]+)".r
    
  input match {
  case  integerPattern(c)=> println("Integer Entered "+input)
  case  stringPattern(a)=> println("String Entered "+input)
  case _ => throw new TypeException(" Exception Occured ")
}
    
   }
   
   
    def main(args: Array[String]) {
      print("Please enter your input : " )
      var line = readLine
      
      println("Thanks, you just typed: " + line)
      try{
         checkType(line)     
      }
      catch {
          case e : Exception => println("Exception Occured : "+e) 
      }
     
    
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.