Error Report Sender ?
Author |
Message |
End Luc
|
Posted: Thu Mar 15, 2012 5:41 pm Post subject: Error Report Sender ? |
|
|
I'm writing a program in java, but if it "Doesn't respond" or "crashes" I want it to execute a file I have called "Error.class" which basically it sends a file called "ERROR.LOG" to the folder specified.
I have it so it makes the file, and writes the message correctly along with the date. but as of actually executing when one of the other 3 .CLASS files crash is the part I'm having trouble with :s
How would I go about making it running a class file if it doesn't respond :s
if you cannot, is there a way around it so you can still send a error report?
thanks Lucas |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Thu Mar 15, 2012 6:03 pm Post subject: RE:Error Report Sender ? |
|
|
There is no generalized way to detect deadlocks or loops which will never end (you run into the Halting Problem: http://simple.wikipedia.org/wiki/Halting_problem).
You can make a heuristic (guess) solution if you have a way of measuring progress and know how long you expect between point A and point B. However, any such solution requires at least one additional thread and some concurrent-programming skills. Based on your description, I don't think you know enough to implement that correctly (yet! keep learning!).
It is much easier to detect a crash, depending on what you mean by "crash". If you want to report exceptions, then do that:
Java: |
try {
// Presumably, these can throw exceptions
firstClass.doStuff();
secondClass.doStuff();
thirdClass.doStuff();
} catch ( Exception e ) { // be more specific about the exception type here, if you can
Error.report ( e );
}
|
If you want to catch JVM crashes (which I doubt you meant), then you need to write that trap outside your Java code--usually in a shell language or a compiled language. |
|
|
|
|
|
Tony
|
|
|
|
|
End Luc
|
Posted: Thu Mar 15, 2012 10:41 pm Post subject: Re: Error Report Sender ? |
|
|
So basically just put the who thing in a giant if statement and then and exception ? :p
would it look like :
code: |
if{
// code goes here
// string called ' Message' here
//string called 'date' here
} catch (Exception e){
// Send Error Report
File file = new File("ERROR_LOG.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(Message + "| Date: ");
output.write(dateDisplay);
output.close();
System.out.println("Your ErrorReport has been sent");
}
|
or did you guys have something else in mind? [/code] |
|
|
|
|
|
Tony
|
|
|
|
|
End Luc
|
Posted: Thu Mar 15, 2012 10:57 pm Post subject: Re: Error Report Sender ? |
|
|
Alright , thanks for the help! |
|
|
|
|
|
DemonWasp
|
Posted: Fri Mar 16, 2012 12:43 am Post subject: RE:Error Report Sender ? |
|
|
@Tony:
code: |
try {
// nothing
} finally {
main(args);
}
|
|
|
|
|
|
|
Tony
|
Posted: Fri Mar 16, 2012 2:05 am Post subject: RE:Error Report Sender ? |
|
|
yes, the article does mention that finally will not execute in case of stack overflow. Or really, anything that will leave JVM in an unstable state. UW's CS343 explores that kind of control flow in under-the-hood details, and it's been one of the best courses I've taken there. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Fri Mar 16, 2012 8:13 am Post subject: RE:Error Report Sender ? |
|
|
Actually, the article deals with C# (and an older version, too), which has different behaviour. In Java, StackOverflowError will run finally{} blocks as it unwinds the stack, just like all other subclasses of Error. You can even catch{} them and handle them. Of course, you're right near the end of the stack, so it's entirely possible your handler will run afoul of the same problem.
Eclipse, for example, has a handler for OutOfMemoryError that I invoke every now and then when I accidentally open an 80MB text file.
You can still trump finally{} with a hard JVM crash, System.exit(), power outage, and some of the deprecated Thread API, such as thread.stop().
CS343 was one of the more useful courses I've ever taken. |
|
|
|
|
|
|
|