Skip to content

Instantly share code, notes, and snippets.

@railsfactory
Created April 27, 2011 06:38
Show Gist options
  • Save railsfactory/943810 to your computer and use it in GitHub Desktop.
Save railsfactory/943810 to your computer and use it in GitHub Desktop.
if I try exception handling
Exception in thread "main" java.lang.VerifyError: (class: mirah/MString, method: to_i signature: ()I) Mismatched stack types
at Usage.main(usage.mirah:2)
if I dont use exception
java Usage
20
Exception in thread "main" java.lang.NumberFormatException: For input string: "20.5"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.parseInt(Integer.java:499)
at mirah.MString.to_i(mirah.mirah:21)
at Usage.main(usage.mirah:9)
package mirah
import java.lang.Integer
import java.lang.Float
class MString
def to_i():int
begin
Integer.parseInt( @s)
rescue NumberFormatException => e
puts e.toString
#ensure
#puts @s
#puts "cant be converted to integer"
#throws NumberFormatException
end
end
end
import mirah.MString
sint = MString.new("20")
sfloat=MString.new("20.5")
puts sint.to_i
puts sfloat.to_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment