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

Can u explain what a java excepion is? please give an example in java programming

pleas be kind when answering

2007-02-15 17:55:06 · 3 answers · asked by angel 1 in Computers & Internet Programming & Design

3 answers

I think this is what you want.

Example:

...
public static void main (String args[]) {
try {
int blah[] = {1,2,3};
System.out.println(blah[4]);
}
catch (Exception e) {
e.printStackTrace();
}
}
...

> java program
java.lang.ArrayIndexOutOfBoundsException: 4
at test.main(test.java:8)

2007-02-15 18:10:52 · answer #1 · answered by SlyMcFly 4 · 0 0

Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. The condition is called an exception. Exceptions are used only for signaling error (exceptional) conditions. For signaling conditions that are part of the normal flow of execution see the concepts of signal and event handler.

In general, current state will be saved in a predefined location and execution will switch to a predefined handler. Depending on the situation, the handler may later resume the execution at the original location, using the saved information to restore the original state. For example, an exception which will usually be resumed is a page fault, while a division by zero usually cannot be resolved transparently.

From the processing point of view, hardware interrupts are similar to resumable exceptions, except they are usually not related to the current program flow.

From the point of view of the author of a routine, raising an exception is a useful way to signal that the routine could not execute normally, for example when its input arguments are invalid (a zero denominator in division) or when a resource it relies on is unavailable (a missing file, or a disk error). In systems without exceptions, the routine would need to return some special error code. However, this sometimes is complicated by the semipredicate problem, in which users of the routine need to write extra code to distinguish normal return values from erroneous ones.

2007-02-16 02:00:46 · answer #2 · answered by xcureanddisease 2 · 0 0

Exception in general is a programming construct with recent languages starting with most new C++, it represents unexpected interruptions to the flow of an application but expected to the computing environment itself.

Example as to how to generate one or dissolving one?

2007-02-16 02:10:30 · answer #3 · answered by Andy T 7 · 0 0

fedest.com, questions and answers