Created
April 27, 2011 06:38
-
-
Save railsfactory/943810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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