I am a c++ programmer , I know little bit about java. I know that java programmers do not have to work with memory directly like C++. I also know that most crashes in C++ appliations are due to memory corruptions.
So can an application written in Java crash due to a memory related issue?
Thanks
Given: Throwable is Exception's superclass.
When I read tests on writing your own 'exceptions', I see examples of Throwable being used in the catch block and other text's show new Exception() being used in the catch block. I have yet to see an explanation of when one should use each.
My question is this, When should Throwable be used and when should new Exception() be used?
EDIT: Inside t...
Are there any guidelines on exception propagation in Java?
When do you add an exception to the method signature?
For example: if an exception is only thrown when an essential program resource is missing, and can only be handled at the top level, do I propagate it through all methods using this exception through all the methods using the erring method?
Are there any good practices? Any bad pra...
If I have an exception in my business layer (e.g. a SQL exception in my JDBC connection bean) how can I propagate it with a custom message to a global error.jsp page? Please help.
I know that this would be bad practice although I know that I would not be able to explain why.
int [] intArr = ...
...
try{
int i = 0;
while(true){
System.out.println(intArr[i++]);
}
}catch(ArrayIndexOutOfBoundsException e){}
I think that you are only supposed to use exceptions for things that shouldn't happen. I am asking this question because I think that I am using exce...
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?
Ok Ill admit I haven't done too much research on this yet, shame on me. It's almost 1 am though and i`m getting lazy to read heh.
Someone please explain the difference between java.lang.RuntimeException and java.lang.Exception? How do I decide which one to extend if I create my own exception?
(I`m C++ programmer learning Java)
THANK YOU! for the quick answers! Now I can go bed cus i choos...
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 ?
Exceptions in C++ don't need to be caught (no compile time errors) by the calling function. So it's up to developer's judgment whether to catch it using try/catch (unlike in Java).
Is there a way one can ensure that the exceptions thrown are always caught using try/catch by the calling function?
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 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
...
I mean, in the definition. If I have a method of a class that implements an interface and I want to throw an exception, how can I do that if the interface don't have a throws declaration.
Thanks
I would like to throw a custom exception that will be determined at runtime. Currently I have to either add throws to the function or surround it with a try catch. What I want is for this exception to not be caught at all. It is a fatal exception and will show the programmer the error and what he can do to fix it. This is for an abstract class checking if initialization has been run first. I wo...
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...
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?
Yesterday I red this article about the new Exception Handling in Java 7.
In the article they show an example (No 4) which is not working in Java 6. I just copied it.
public class ExampleExceptionRethrowInvalid {
public static void demoRethrow()throws IOException {
try {
// forcing an IOException here as an example,
// normally some code could trigger this.
throw ...
As I know if method throws an exception Java compiler forces the caller of that method to catch that exception.
I see that parseInt throws NumberFormatException :
public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
So why I can call it wthout catching the exception :
String str = "5";
int n = Integer.parseInt(str);
Imagine I have the methods:
public static void funcA() {...}
public static void funcB()
{
byteBuffer.wrap(someByteArray, 0, someByteArra.length);
}
IN JAVA API:
public static ByteBuffer wrap(byte[]array, int offset, int length)
{
try {
return new HeapByteBuffer(array, offset, length);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();...
I just started to learn Java. There is a course in MIT and there is an assignment to write a class for pay calculation. Part of the task is:
The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.
If the number of hours is greater than 60, print an error message.
The code I have written is as follows:
public class fooCorporation {
privat...
I would like to handle errors with (unchecked) exceptions. I heared that for each kind of exception I should create a subclass of either Error or RuntimeException.
What's the difference?