Académique Documents
Professionnel Documents
Culture Documents
checked exception
These are exceptional conditions that a well-written
application should anticipate and recover from.
Runtime-exception
These are exceptional conditions that are internal to the
application, and that the application usually cannot anticipate
or recover from. These usually
programming bugs, such as
logic errors or improper use of an API.
Error
These are exceptional conditions that are external to
the application, and that the application usually cannot
anticipate or recover from. For example, suppose that an
application successfully opens a file for input, but is unable to
read the file because of a hardware or system malfunction
try
The first step in constructing an exception handler is to
enclose the code that might throw an exception within a
try block.
catch
You associate exception handlers with a try block by
providing one or more catch blocks directly after the
try
block. No code can be between the end of the try
block and
the beginning of the first catch block.
try {
} catch (ExceptionType name) {
} catch (ExceptionType name) {
}
finally
The finally block always executes when the try block
This ensures that the finally block is executed even if an
unexpected exception occurs.
exits.
throws
The throws keyword in java programming language is
applicable to a method to indicate that the method raises
particular type of exception while being processed.
throw
All methods use the throw statement to throw an exception. The
throw statement requires a single argument: a throwable
object.
Throwable objects are instances of any subclass of the Throwable
class. Here's an example of a throw statement.
throw someThrowableObject;
import java.io.*;
public class exceptionHandle{
public static void main(String[] args) throws Exception{
try
{
int a,b;
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
a = Integer.parseInt(in.readLine());
b = Integer.parseInt(in.readLine());
}
catch(NumberFormatException ex){
System.out.println(ex.getMessage() + " is not a numeric value.");
System.exit(0);
}
}
}
import java.io.*;
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}if (out != null) {
out.close();
}
}}}
FlowLayout
BorderLayout
GridLayout
GridBagLayout
CardLayout