Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to trap some errors?

Author
Message
ale870
19
Years of Service
User Offline
Joined: 17th Jan 2007
Location:
Posted: 10th Jan 2013 23:56
Hello,

if I use the function "SAVE OBJECT" and the object DBO already exists, the game stops and show me an error (game quit).
How can I "trap" the error in order to prevent program lock?
I wish something like "on error goto" or "try..except".

Thank you!

--Alessandro
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 11th Jan 2013 02:39
options are kinda limited in dbpro, you can check whether an object or file or whatever exists and then do or dont do something based on that. basically rather than handle an error, stop yourself from raising one to start with.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jan 2013 03:13
With STYX there is a function called:

ERROR TRAPPING OFF


and

ERROR TRAPPING ON


and

GET LAST ERROR


and

RAISE ERROR


[Typos in the code above is not that of mine, I simply copy+pasted]

To give an explanation of how you would use this functionality...

First lets say you have a block of code that you either wish to test against, but allow the program to continue past and run the rest of the program... or a section of code you are certain may be prone to error based on external events for example...

This is the code sample that comes with STYX, I have yet to get the raise error to work, but it is a life saver to stop the application dying...



Although it says it is intended for CORE FUNCTIONS...

An example from me would be, say you was using DarkPhysics... and you had your program in a modular fashion and did not look at your start block, where you would place the call to "PHY START" and later you created a call to make an object into a PHY object by calling PHY MAKE RIGID BODY DYNAMIC BOX, I would place the error trapping before this and then turn it back on after, the program will not die and you will see that the effect was not applied... you could then apply your own error calls in your own way for such accounts and still resume the application...

I plan to make EEVs on this, so stay tuned

I do not know if Matrix1Utils has such a feature, but you are welcome to check into that yourself...

Hope this helped...

ale870
19
Years of Service
User Offline
Joined: 17th Jan 2007
Location:
Posted: 11th Jan 2013 10:28
Thank you to everone, both the solutions are very good (and I have STYX module!).

For my problem now I will adopt the solution to "prevent" (check file existence), but I'm sure I will use STYX solution in other situations!

Thank you again!

--Alessandro
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 11th Jan 2013 18:25
Matrix1 can jump to a function on an error:



HTH,

James

Login to post a reply

Server time is: 2026-07-08 21:14:38
Your offset time is: 2026-07-08 21:14:38