Closed salino closed 9 years ago
Have tried with
boost::expected <int>
?
Sorry. I don't quite understand how this should help. Could you please elaborate?
Nevertheless, I replaced all boost::expected <int, MyException>
with boost::expected <int>
but now return boost::make_unexpected ();
doesn't compile because it needs an input argument.
When you use expected <int, MyException>
the exception throw is not MyException
but bad_expected_access
which has "Found an error instead of the expected value."
as result of a call to what()
.
Could you show me the compile errorr?
Have you changed
return boost::make_unexpected (MyException ());
by
return boost::make_unexpected ();
Why?
Ah, now I understand. I first imagined I had to specify the thrown exception in the expected class. But the way it is is much cleaner.
This works as 'expected' :-)
boost::expected <int> unexpected ()
{
return boost::make_unexpected (MyException ());
}
Thanks a lot for your help.
Hi.
Please have a look at this example. It prints out
but I would like it to output something like this:
Is there a way to do this without having to modify the code on the client side (main ())?
Here is the full source: