What is considered the best, most comprehensive way to close nested streams in Java? For example, consider the setup:
FileOutputStream fos = new FileOutputStream(...)
BufferedOS bos = new BufferedOS(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
I understand the close operation needs to be insured (probably by using a finally clause). What I wonder about is, is it necessary to e...
I'm trying to learn more about basic Java and the different types of Throwables, can someone let me know the differences between Exceptions and Errors?
Documentation for java.lang.Error says:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch
But as java.lang.Error is subclass of java.lang.Throwable I can catch this type of throwable.
I understand why this is not good idea to catch this sort of exceptions. As far as I understand, if we decide to caught it, the catch ...
To the point: how would you handle a server-side HTTP 4nn/5nn errors in jQuery's ajax requests? This case concerns a JSP/Servlet webapplication at the server side. Here I am not talking about trivial runtime exceptions such as NullPointerException and so on. Assume that they're all handled perfectly. A good example of such a HTTP 4nn/5nn error is 401 unauthorized (insufficient user rights) and ...
Sometimes I see
try {
}catch(Throwable e) {
}
And sometimes
try {
}catch(Exception e) {
}
What is the difference
Is there any point catching an out of memory error (java.lang.OutOfMemoryError) in Java?
I'm a student and right now going through exceptions and errors in Java.
I have a confusion about when error occurs. Please share with me some examples.
I was told that in Java, unchecked exceptions can be caught in a try block, but if it's caught, isn't it called a checked exception?
I want to ask why we don't have to add try-catch block to a RuntimeException while we should do that with other exceptions?
I mean like :
public class Main {
public static void main(String[] args) {
throw new RuntimeException();
}
}
Edit :
when I say : throw new RuntimeException(); it is so clear that there is an exception will happen ,so why the compiler doesn't forbid that ?
I have to serialize around a million items and I get the following exception when I run my code:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at org.gi...
They are very different kind of languages and the way they handle exceptions might be rather different.. How is exception handling implemented and what are the implementation difference within these languages?
I am asking this question also because I noticed that C++ exception handling seems to be very slow compared to the JavaScript version.
Hi
this was the question me in the interview. What is the main difference between Unchecked exception and error as both are not caught.They will terminate the program. I was bit puzzled.
Can anybody elaborate on this.
I have a thread in a Java web application that causes a java.lang.OutOfMemoryError: Java heap space exception, but the try/catch block does not catch the error.
Sample code:
private void doSomeWork()
{
try
{
processData(); //Causes OutOfMemoryError
System.out.println("This line does not execute");
}
catch (Exception e)
{
System.out.println(...
I am trying to understand the Java Error class. I have a good understanding of the Exception class, but can't find examples of code for the Error class. I've tried searching the web and also the java.sun website, but I'm not finding anything useful to help me understand this better.How to use Error class in programs and where we have to use that?
What type of exception is caught by the beanshell catch(ex): Exception or Throwable?.
Example:
try {
.... } catch (ex) { }
I am trying to add a custom throws clause to a method definied by an interface. This is not possible. How could I bypass it? Here is some code:
private void sendRequestToService(final ModuleRequest pushRequest)
{
ServiceConnection serviceConnection = new ServiceConnection()
{
public void onServiceConnected(ComponentName name, IBinder service)
{
try
...
What is the best practice when dealing with Errors within a server application?
In particular, how do you think an application should handle errors like OutOfMemoryError?
I'm particularly interested in Java applications running within Tomcat, but I think that is a more general problem.
The reason I'm asking is because I am reviewing a web application that frequently throws OOME, but usuall...
My project got like 20 unhandled exceptions, doesn't matter why, and I was wondering how do they affect the JVM? It doesn't crash, but I'm still wondering what are their footprint in JVM. Where do they go?
Is it a bad practice to catch the Throwable?
For example something like this:
1. try {
2. // Some code
3. } catch(Throwable e) {
4. // handle the exception
5. }
Is this a bad practice or we should be as specific as possible?
Thanks!
I'm working on a cross platform application in Java which currently works nicely on Windows, Linux and MacOS X. I'm trying to work out a nice way to do detection (and handling) of 'crashes'. Is there an easy, cross-platform way to detect 'crashes' in Java and to do something in response?
I guess by 'crashes' I mean uncaught exceptions. However the code does use some JNI so it'd be nice to be a...
As we know if any error or any unchecked exception occurs then our program will halt, then what are the differences between those?