YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Throwing new exception object (or table) from C++
pointer
#1 Posted : Friday, December 16, 2016 12:04:53 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/16/2016(UTC)
Posts: 3

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Folks,

I have another question, regarding thorwing new exception object to script from c++.

For example I would like to have exception like:

Code:

class Exception
{
       code = 2;
       message = "Access violation";
}


Can anybody give me c++ snippet how to generate such exception with ps_throwobject() or other function?

So I would except to use it like from sq:

Code:

try
{
   mkdir("/some/folder");
}
catch (ex)
{
    print(format("%d: %s\n", ex.code, ex.message));
}



So I would expect that console would print:

Code:

2: Access violation
absence
#2 Posted : Saturday, December 17, 2016 3:55:29 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
I only used sq_throwerror so far, however I'd think you would do it like this:

SQInteger MyFunction(HSQUIRRELVM v)
{
[...]

if (errorcondition) {
//create ErrorObject on the stack here, for example using sq_newtable, sq_newslot and the like
sq_throwobject(v); //pushes top of stack as exception object
return(SQ_ERROR) ; //not sure about this, because this may ADDITIONALLY cause an exception. If not working properly, try return(0) ;
}

[...]
return (0) ; //or push return value, then return(1) instead;
}
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.116 seconds.