English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

public class Simple5 {

public static void main(String[] args) {

try {
method(0);
} catch (UnsupportedOperationException ex) {
ex.printStackTrace();
}
}

private static void method(int n) throws UnsupportedOperationException {

// Do whatever you want to here
if (n >= Integer.MIN_VALUE && n <= Integer.MAX_VALUE) {
// This can never be false, it will always happen.
throw new UnsupportedOperationException("Just testing.");
}
}
}
Should produce:

java.lang.UnsupportedOperationException: Just testing.
at Simple5.method(Simple5.java:17)
at Simple5.main(Simple5.java:6)

2006-07-21 10:22:08 · answer #1 · answered by Mark aka jack573 7 · 0 0

well there are three ways to use exception handling

the best way is a conditional statement to catch the exception
if { error condition }
then { so and so }

if this will not work then
you can do this

try { code/algorithm that may have an error }
catch { exception e}
catch { another exception f}

the e/f is a variable to store the exception
because you can call upon it later on to get details on the specific error

the third way to handle it is when you actually want to stop the program itself to prompt the programmer or user of an error that needs to be addressed

throw {exception}

im pretty sure the syntax is accurate, but you might want to check it over

2006-07-17 17:52:34 · answer #2 · answered by ANBU 2 · 0 0

Sorry priya its hard to give a program satisfying ur requirement.
and exceptions are really hard to remember.
try,catch,throw,throws and finally are the key words related to exception handling concepts.a catch should have a try but a try can be without catch but should have finally with it.

2006-07-17 17:53:19 · answer #3 · answered by kanna 3 · 0 0

fedest.com, questions and answers