Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the .NET equivalent of Java's NumberFormatException?

Is FormatException in .NET the equivalent of NumberFormatException in Java ?

like image 291
Xris Avatar asked Dec 14 '11 09:12

Xris


People also ask

What type of exception is NumberFormatException?

The NumberFormatException is an unchecked exception in Java that occurs when an attempt is made to convert a string with an incorrect format to a numeric value. Therefore, this exception is thrown when it is not possible to convert a string to a numeric type (e.g. int, float).

Is NumberFormatException a runtime exception?

The NumberFormatException occurs when an attempt is made to convert a string with improper format into a numeric value. That means, when it is not possible to convert a string in any numeric type (float, int, etc), this exception is thrown. It is a Runtime Exception (Unchecked Exception) in Java.

How do I fix Java Lang NumberFormatException for input string?

To avoid this error, you should trim() the input string before passing it to parse methods like the parseInt() or parseFloat().

How do I resolve Java Lang NumberFormatException null?

NumberFormatException: For input string: "null" is specifically saying that the String you receive for parsing is not numeric and it's true, "null" is not numeric. Many Java methods which convert String to numeric type like Integer. parseInt() which convert String to int, Double.


2 Answers

I think yes both are same following are the details given about both Exception

NumberFormatException (java) : -Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

FormatException (.net) : - FormatException is thrown when the format of an argument in a method invocation does not match the format of the corresponding formal parameter type. For example, if a method specifies a String parameter consisting of two digits with an embedded period, passing a corresponding string argument containing only two digits to that method would cause FormatException to be thrown.

FormatException uses the HRESULT COR_E_FORMAT, which has the value 0x80131537.

refer http://msdn.microsoft.com/en-us/library/system.formatexception.aspx

http://docs.oracle.com/javase/6/docs/api/java/lang/NumberFormatException.html

like image 97
Hemant Metalia Avatar answered Oct 07 '22 16:10

Hemant Metalia


Yes. Methods like Double.Parse throw a FormatException if the string to be converted does not represent a number in a valid format.

like image 26
kol Avatar answered Oct 07 '22 18:10

kol