answersLogoWhite

0

Yes or course...

Of course,java provides the try-catch construct to handle this proplem.You just need to throw out you unconventional codes in try construct and handle it in catch construct.Here is an example:

import java.io.*;
import java.io.IOException;
import java.io.InputStreamReader;
public class Sorter{
public static void main(String args[])throws NumberFormatException,IOException,NopositiveException
{
try{
PutIn in=new PutIn();
in.Order();
in.Out();
}

catch(NopositiveException e)//handle user defined exception

{
System.out.println(e.toString());
}
catch(NumberFormatException e)//handle java's exception
{
System.out.println("it's not number!");
}
}

}
class PutIn
{
int number[]=new int[10];
PutIn()throws IOException,NopositiveException
{
String str[]=new String[10];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<10;i++)
{
str[i]=br.readLine();
if((Double.parseDouble(str[i])-(int)Double.parseDouble(str[i]))!=0)//if it si a int type
{
NopositiveException exception=new NopositiveException(str[i]);
throw exception;//throw exception
}
else
number[i]=Integer.parseInt(str[i]);
}
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Where does source code come from in java?

Source code comes from the programmer...


What is a Java programmer?

A computer programmer who uses the Java language.


What is Logic error in java programming?

Logical errors are grammatical errors or mistakes made by a programmer in java, it may not affect the program design but it can change the context of the statements.


When should we use exception handling in java?

Exception handling should be used in Java in all cases where you as a programmer suspect that your code might throw some exceptions or create errors that might look ugly when a user is using the application. In such cases you use exception handling to catch and handle the exception and exit gracefully. You use the try - catch block in Java for exception handling.


What is the difference between implicit and explicit Java programming?

Explicit means done by the programmer. Implicit means done by the JVM or the tool , not the Programmer. For Example: Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor. Explicit is opposite to this , ie. programmer has to write .


Can you extend error in java?

Yes, in Java, you can create custom error types by extending the Error class or its subclasses. This allows you to define specific error conditions for your application. However, it's generally recommended to extend the Exception class instead, as Error is intended for serious issues that a reasonable application should not try to catch. Custom exceptions provide better error handling and recovery mechanisms in your code.


It is not an error not to end a Java file name with the java extension?

If you want to compile a java program the name of that source code must end with extension .java


What jobs make 125000 a year?

depends on what you're good at. if you're a programmer (computer person) then you could find a job with someone like Google or Sun Microsystems (java, openoffice) as a java programmer or writing code in html or something for webpages


What is a good Java book for experienced non-Java programmer?

Java cook book


What is an Program compilation?

That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.


What language should you start to code in as a Game Programmer?

JAVA or PYTHON. These are quite easy to use and very much user friendly.


Define Syntax Error in computer?

A syntax error is a scenario in programming where the code that is written by a programmer which is incorrect as per the language structure. For example I say the following statement in English: it is syntactically wrong: I currently in write java questions for wikianswers yesterday and tomorrow all day short. If you see the above statement, it is grammatically wrong. That is exactly what a syntax error is for a java program. It is incorrect as per the programming language specifications.