Exceptions and errors in Java are inherited from Throwable,exception and are divided into runtime exceptions (runtimeexception) and compile-time exceptions.
Run-time exception is the logic of the program is not rigorous or specific conditions under the program error, such as division when the divisor is 0, runtime exception Java is not required to Try,catch to capture. We debug the code to reduce the run-time exception, as the code debugging run-time exception is captured, the program's robustness has been improved.
Compile-time exceptions such as file not found exception, IO exception, SqlException, etc., these are predictable exceptions (checked Exception), unlike runtime exceptions that are unchecked Exception. In our code for file reads, these exceptions must be captured and handled appropriately during IO operations.
The minimum operation after an exception capture is to log logs to be documented. Throw an exception if necessary, and let the upper-level call code know that there has been an exception.
The method throws a new exception with the throw, and the method declaration throws an exception with the throws, which is also to be noted.
A subclass method throws an exception that is less or equal than the exception thrown by the parent class method, and the subclass method throws only the exception that the parent method throws or its subclass, not its parent class.
Error refers to an error in the bottom of the JVM, which is not controlled by the program, such as Stackoverflowerror,outofmemoryerror.
The common code for file loading is as follows:
InputStream is = new FileInputStream ("Src/test.properties");
This way of writing is the file once changed the path also to modify, and packaged into a running program, there is no src directory, you can also use the following method to load the file:
InputStream is = FileLoadTest.class.getClassLoader.getResourceAsStream (test.properties);
At this time as long as test.properties in Classpath below can, and specific path independent.
Java Foundation throwable, file loading