Difficulty with error handling

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 04 April 2009   #1
Difficulty with error handling

 (
global rltTest
try destroyDialog rltTest catch()
 
rollout rltTest ""
(
	pickbutton pbObject "Pick" 
	button btnDoIt "Do it"
 
	local theObject
 
	on pbObject picked obj do
	(
		theObject = obj
	)
 
	on btnDoIt pressed do
	(
		theObject.name = "myObject"
		theObject.pos = [0,0,0]
	)
)
createDialog rltTest 60 60
)

In the code above, someone pointed out that if the user picks the object, then deletes it and presses the Do it button, then the script crashes.
I've searched the reference to find a way for the script totrelaunch itself and the closest I could find was this:
 try theObject.name = "myObject" catch(fileIn (getSourceFileName())) 


Still, no joy. The script does restart, thus replacing the dialog by a new one. But at the same time it crashes at the next line. Beep + error in the listener.

How can I deal with this error?
 
Old 04 April 2009   #2
Hi Pat,
rather than restarting the script after crash, avoid it by wrapping your code in a node validity test. If it's valid, execute the code, otherwise do nothing and reset the node storing variable.


(
    rollout rltTest ""
    (
        pickbutton pbObject "Pick" 
        button btnDoIt "Do it"
     
        local theObject
        on pbObject picked obj do
        (
            theObject = obj
        )
     
        on btnDoIt pressed do
        (
            -- Generic Node Validity Test Condition
            if (isValidNode theObject == true) then
            (
                theObject.name = "myObject"
                theObject.pos = [0,0,0]
            )
            else
            (
                theObject = undefined
            )
/*
            -- OR: Specific Node Deletion Test Condition
            if (isDeleted theObject == false) then
            (
                theObject.name = "myObject"
                theObject.pos = [0,0,0]
            )
            else
            (
                theObject = undefined
            )
*/
        )
    )
    try (destroyDialog rltTest) catch()
    createDialog rltTest 60 60
)

- Enrico
__________________
IllusionCatalyst Instrument set for 3ds Max │ AliquaForma Personal portfolio in fieri
 
Old 04 April 2009   #3
Hello Caprier,

MXS has a general event callback system which is called when a node is deleted. search for callbacks in the help.
Also, there is a the "when construct" although I would recommend the first option since it is much less intensive


fn whatnode=
(
 n=callbacks.notificationparam()
 format "node deleted:%\n" n
)

callbacks.addscript #nodepredelete "whatnode()" id:#nodetest
/*
callbacks.removescripts id:#nodetest
*/



Josh.
__________________
www.joshuanewman.net
 
Old 04 April 2009   #4
*You could make the DO IT button grayed out and enable it only when a valid object has been picked with the PICK button.

*You can check if the object is valid (if isValidNode theObject then ...) inside the DO IT handler so even the object is deleted between the pick and do it clicks it would not crash.
__________________
Bobo
 
Old 04 April 2009   #5
Guys, thank you for all the answers.

@SyncViews and Bobo: your suggestion makes perfect sense. I don't know why but I was a little reluctant to put 100 lines of code into a single test block. Is it common practice?

@j-man: I like the idea of a callback. So it could disable the DoIt button if the picked object is deleted, forcing the user to pick another one. Now I just have to figure out the syntax...
 
Old 04 April 2009   #6
Great! I've finally got my mind around the callback mechanism and now it works like a charm.
Thanks a lot, people! Have a bear on me!!
 
Old 04 April 2009   #7
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:47 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.