[Closed] Ideas for Error Handling
I would like to improve my error handling.
How do you guys handle errors in your code? I especially want the users of the scripts to get a more pleasant experience if the program crasches.
Do you create try functions everywhere or?
I will implement a special function that tries to shut everything down, displays a windows with the error message (a post bug report button) and perhaps a description field where they can explained what caused the problem. Now I’m wondering should I apply try experessions everywhere that links to this function?
Any other ideas?
/Andreas
Usually I’ll have a function set up to disable the UI except for, say, a “Refresh” button, but I try not to let it ever execute (o.c.d.) :). But like you said, a try expression with the catch pointing towards your disable function is usually what I do.
[left]I think I will do something like this:[/left]
[left] [/left]
[left]a try section in every function. The catch section calls ErrorClass “Function Name”[/left]
[left]so I can also send comments into the errorclass, perhaps variables.[/left]
[left]the errorclass gets a throw. I call a Cleanup procedure that closes the interface with as safe a function as possible and repaints the viewports. A program specific cleanup function can also be called that for example deletes variables.[/left]
[left]- A windows popup with A standard error Message “We are sorry a bug occured. bla”. Also the error report is printed in a window (hidden by defaul but can be opened). By a keypress the user can send this by mail to the author.[/left]
[left]- A log could also be created perhaps and saved on disk.[/left]
[left] [/left]
[left]Any comments?[/left]
[left]/Andreas[/left]
[left] [/left]
i use try(throw “error”)catch(format “%
” getCurrentException())
my scripts are very modular, i have a lot of basic functions, then higher level functions that use those, and then the user interface / macroscripts that use the higher level functions
this try()catch() stuff works great for that because if there’s a try()catch() in every level, a bug in the lowest level function will trigger the catch in the highest level function, so it causes everything to stop, which is usually what you’ll want and you can do the cleanup in the highest level only
Now. I’m wondering. What do you guys think would be the best way to submit the error report (optional of course for the user).
I think it would be good to get the report by mail. What would be the best way to send a mail from maxScript that has the error report in it?
/Andreas
I’m trying the ActiveX example with a mail, but I get an error when I run it.
>> MAXScript Rollout Handler Exception: – Runtime error: Cannot create the ActiveX control: {248DD896-BB45-11CF-9ABC-0080C7E7B78D}
Reported error message: Class not registered
I found this thread but it didn’t help that much
http://forums.cgsociety.org/showthread.php?t=296038&highlight=mail
I’m wondering, wouldn’t it be possible to contact a php script on my server and send the mail from there?
/Andreas
You could create an hyperlink control “Send error report” and define the target URL as “www.yourdomain.com/errorreport.php?subject=ScriptError&body=ErrorMessageBla”
If the User clicks on the Hyperlink it will open an browser window and send you an email…
Chris
That is a nice idea. I will refresh my php knowledge a little bit, but that should do it I think.
Is there a limit to the lenght of text that you can send with the PHP message?
I probably need to send 2 pages of information with an error report.
/Andreas
It’s pretty easy to send an email with php:
<?php
$to = "email.guide@about.com";
$subject = "Hi!";
$body = "Hi,
How are you?";
if (mail($to, $subject, $body))
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>
You just have to replace the subject and the body with the actual url parameters. The length of the parameters are limited to 1024 characters as far as I know. Please note that you have to replace characters like “&” to “%26”.
Chris
Thanks for the help Chris.
Hmm. The 1024 chars may be a problem. Most errors from maxScript are usually a few pages long, could very well be more than 1024 chars. Perhaps it would be worth considering having a standalone app that the script calls.
Hm, I just checked a standard bug information and got 2000 chars.
What I could do is first compress the information by deleting the unuseful information. For example “undefined” could be changed to “uf”. I could also split the message into several mails so that I perhaps send 3 mails in one go.
/Andreas
Another idea could be to build a html site locally, that redirects to the real url.
However since the user doesn’t have a server for calculating the php, can it actually send POST data in any good way? It should work to redirect and have the data in the url (like you guys suggested), but then I still have the 1024 char limit.
Perhaps the best way would just to have a mail link in the error message, and display the error report so they can copy it. This way they have to cut+paste the error message into their mail message. The bonus is that it’s easier for the user to attach images of the problem and to write a description of the problem. The downside is that it needs a few more clicks from the user.
/Andreas