PDA

View Full Version : Ideas for Error Handling


f97ao
02-06-2006, 07:23 PM
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

d3coy
02-07-2006, 04:53 AM
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.

f97ao
02-07-2006, 10:09 AM
I think I will do something like this:

a try section in every function. The catch section calls ErrorClass "Function Name"
so I can also send comments into the errorclass, perhaps variables.
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.
- 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.
- A log could also be created perhaps and saved on disk.

Any comments?
/Andreas

Aearon
02-07-2006, 10:29 AM
i use try(throw "error")catch(format "%\n" 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

f97ao
02-07-2006, 01:51 PM
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

f97ao
02-07-2006, 05:51 PM
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

MrSparkle
02-10-2006, 09:17 AM
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

f97ao
02-11-2006, 09:22 AM
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

MrSparkle
02-11-2006, 03:59 PM
It's pretty easy to send an email with php:


<?php
$to = "email.guide@about.com";
$subject = "Hi!";
$body = "Hi,\n\nHow 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

f97ao
02-11-2006, 11:19 PM
It's pretty easy to send an email with php:

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

f97ao
02-12-2006, 12:09 PM
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

rdg
02-12-2006, 03:03 PM
f97ao,
sending data via POST is done by the browser not by PHP.
PHP recieves the data.
So can build a local html file display it in the browser and have the data send via POST to a url on your server.

edit: I don't think there is a 1024 limit with POST, GET has a limit for sure ...
But there are ways to upload MB images with POST.

Georg

f97ao
02-13-2006, 08:38 AM
f97ao,
sending data via POST is done by the browser not by PHP.
PHP recieves the data.
So can build a local html file display it in the browser and have the data send via POST to a url on your server.

edit: I don't think there is a 1024 limit with POST, GET has a limit for sure ...
But there are ways to upload MB images with POST.

Georg

Thanks Georg, you are right, it's not php that sends the data, but user forms. :)

Pfew, just put in 25 hours in the weekend on the new Interface. Hope to do the error report and auto update next.

/Andreas

MrSparkle
02-13-2006, 09:04 AM
I have some more ideas:
the first - and very simple - one is to use an mailto-link with a hyperlink component in maxscript, so the user will send the error report with his own email client. The mailto-syntax is explained here: http://www.outfront.net/tutorials_02/adv_tech/mailto.htm

I think that there are less than 1k characters provided if you use the mailto-link but it's made very easy. Another idea is to generate a HTML code within maxscript that includes code for a POST form with your email and you error message and a button that let the user send you the message, e.g.:


<form method="post" action="www.yourdomain.com/errormsg.php">
<textarea name="ErrorMsg">
YOUR ERROR MESSAGE HERE (> 1024 Characters!)
</textarea>
</form>


You could display that HTML page using the InternetExplorer ActiveX Component which is availlable on almost every Windows PC. MaxScript does support ActiveX components, so maybe this idea could work...

Chris

f97ao
02-19-2006, 09:18 AM
I have some more ideas:
the first - and very simple - one is to use an mailto-link with a hyperlink component in maxscript, so the user will send the error report with his own email client. The mailto-syntax is explained here: http://www.outfront.net/tutorials_02/adv_tech/mailto.htm

I think that there are less than 1k characters provided if you use the mailto-link but it's made very easy. Another idea is to generate a HTML code within maxscript that includes code for a POST form with your email and you error message and a button that let the user send you the message, e.g.:


<form method="post" action="www.yourdomain.com/errormsg.php">
<textarea name="ErrorMsg">
YOUR ERROR MESSAGE HERE (> 1024 Characters!)
</textarea>
</form>


You could display that HTML page using the InternetExplorer ActiveX Component which is availlable on almost every Windows PC. MaxScript does support ActiveX components, so maybe this idea could work...

Chris

Chris, Do we need a button to send the POST data? Can't the webpage just redirect directly and send post data?

One way that could work without having and ActiveX component is just to use the Shell command to launch the page.

Going to work on this this evening. I will come back when I have figured out something more.
/Andreas

MrSparkle
02-19-2006, 01:14 PM
Hi Andreas,

JavaScript can do this. You could insert an JavaScript command at the end of the HTML page (to be sure, the page has successfully loaded):


<script labguage="JavaScript">
<!--
document.forms[0].submit();
-->
</script>

Hope, this helps,
Christian

f97ao
02-19-2006, 03:13 PM
Hi Andreas,

JavaScript can do this. You could insert an JavaScript command at the end of the HTML page (to be sure, the page has successfully loaded):


<script labguage="JavaScript">
<!--
document.forms[0].submit();
-->
</script>

Hope, this helps,
Christian

Ah, thanks, that should do the trick.
/Andreas

CGTalk Moderation
02-19-2006, 03:13 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.