java - How to throw exception for statment? -


Hello! I want to throw exceptions for the line.

  barcode no = long.partial long (jTextField1.getText ())   

I did it in a way / P>

  not barcode = long.parseong (jTextField1.getText ()) New numberFormat exceptions throw ("Enter numbers only");   

But in this manner the compiler error says ";"

">

If the text is not in the correct format then message , then you have to catch the exception and throw a new one:

 Try  {barcode = long.parsling (jTextField1 gettext ());} hold (NumberFormatException e) {new number FormatAccertation ("Enter numbers only");}   

I Do not suggest that you send a user-view message Trying to use the exception message as sh - though they are more appropriate for logging from appearing to the end user.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -