GINAC

I'm using ginac (is not algebra compumputer) in ubuntu
I've installed ginac-tools and libginac-dev
I would like throw a syntax error using
a bad formula ( without a bracket for example) and I would like catch it in a block try catch in c++
What can I do?
This code doesn't work for me:

#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
symbol x("x"), y("y");
ex poly;
for (int i=0; i<3; ++i)
try{
poly += factorial i+16)*pow(x,i)*pow(y,2-i);
}
catch(int e){
cout<< "Error" << e << '\n';
}
cout << poly << endl;
return 0;
}

compile with the option -lginac

thanks

You're assuming that an int is being thrown.

Assuming a standard exception is being thrown, try the following:
1
2
3
4
catch (exception& e)
  {
    cout << e.what() << '\n';
  }


If you're unsure what can be thrown, you can also include a default catcher:
1
2
   catch (...) 
   { cout << "default exception"; }


http://www.cplusplus.com/doc/tutorial/exceptions/

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Topic archived. No new replies allowed.