How to raise OgreException

zariduomega

20-08-2009 16:26:50

Forgive me if this is a stupid question, but what kind of object is typically passed into the OgreException class constructor? From looking at the class definition in _ogre_exceptions_.py it looks like an object that has the getFullDescription method (from looking at the __str__ method), but this class bears little similarity to the C++ OgreException class

The reason I ask is that I want to raise an OgreFileNotFoundException if a given file cannot be located, but I want to do it correctly so that try-except blocks can handle it just like other OgreExceptions.

Thanks in advance!

kendoran

25-08-2009 14:41:36

I'm very new to ogre and python-ogre (maybe somebody else has a better solution :D ), however something like the code I wrote up below may be what you're looking for. Not sure about the value for "errorCode", however this should be enough for you to build on:


#!/usr/bin/env python

import ogre.renderer.OGRE as ogre
import ogre.renderer.OGRE._ogre_ as ogreInternal
import ogre.io.OIS as OIS
import array
import code
import sys
import os
import inspect

def lineno():
"""Returns the current line number in our program."""
return inspect.currentframe().f_back.f_lineno

class ExceptionThrower(object):
def __init__(self):
filename = os.path.basename(sys.argv[0])
errorDesc = "Description of error"
errorCode = 3
exInfo = ogreInternal._FileNotFoundException_(int(errorCode), errorDesc, self.__class__.__name__, filename, long(lineno()))
raise ogre.OgreFileNotFoundException(exInfo)

if __name__ == '__main__':
try:
ExceptionThrower()

except ogre.OgreException, e:
print e