Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with try/catch

Status
Not open for further replies.

gmarkey

Programmer
May 29, 2003
2
AU
G'day
I dont seem to be able to get a trycatch block to work.
the code is..
try{
xmlpp::DomParser parser;
parser.set_validate();
parser.parse_file(fileName);
if(parser){
xmlpp::Node *pNode = parser.get_document() ->
get_root_node();
...
}
}catch(const std::exception& ex){
textWindow -> insert(ex.what()); //line 276
}

if I compile this code I receive the following..

file.cxx: In static member function 'static void file::parseFile(char *):

file.cxx:276: 'ex' undeclared(first use this function)

it does'nt seem reasonable that ex is undeclared here --
doesnt line 275 declare it?

if I commect out line 276 the program compiles and links fine. However it crashes on an improper .xml file.
the output from gdb on the appropriate lines are..

(gdb)n
parser.parsefile(fileName);
(gdb)n

program received signal SIGABRT, Aborted
0xffffe002 in ??()

the code above is basically a cut and paste from an example program from libxml++. the parser should throw some exception. I cant see why a) ex is not seen? and b)given that I comment it out that an exceptionis not caught?

If you have any ideas I would appreciate a response -- I'me very new to c++ but this seems like a standard try/catch block.
thanks in advance.
 
An exception is a wrapped string, try getting rid of the pass by reference, perhaps ex is dieing before it reaches the catch. Moeover, you could catch the exception with a

catch(...) and then display your own error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top