[vtkusers] question about vtk error macro

Jeff Baumes jeff.baumes at kitware.com
Mon Nov 22 09:11:37 EST 2010


If you start with a string literal, then the form:

vtkErrorMacro("string")

or

vtkErrorMacro("string" << variable << ", " << more_stuff);

works fine. If you need to start with a variable, then to effectively put
the "<<" before the "x" in your example, you need to start with "<<":

vtkErrorMacro(<< fname << " invalid");

Indeed, not starting with "<<" is a shortcut that only works with string
literals. Many places in VTK start the error macro with "<<" when needed.

Jeff

On Sat, Nov 20, 2010 at 7:27 PM, Mark Roden <mmroden at gmail.com> wrote:

> I should add, this is with visual studio 2008 on a windows 7 machine, 64
> bit compiler.
>
>
> On Sat, Nov 20, 2010 at 4:13 PM, Mark Roden <mmroden at gmail.com> wrote:
>
>> Hi all,
>>
>> I'm having a problem with the vtk error macro, and was hoping someone
>> could shed some light on the issue.
>>
>> The relevant lines for this problem start on line 467 of vtkGetSet.h from
>> the git head:
>>
>>      vtkmsg << "ERROR: In " __FILE__ ", line " << __LINE__      \
>>             << "\n" << self->GetClassName() << " (" << self     \
>>             << "): "  x << "\n\n";                            \
>>
>> If x is a std::string, the above fails to compile, but the following is
>> fine:
>>
>>      vtkmsg << "ERROR: In " __FILE__ ", line " << __LINE__      \
>>             << "\n" << self->GetClassName() << " (" << self     \
>>             << "): " << x << "\n\n";                            \
>>
>> Note the extra << right before x.
>>
>> I'm doing this to debug a problem in the vtkGDCMImageReader I'm having
>> where images aren't being read in Java, but are read just fine in C++-- I
>> think that there's a problem with string termination, but I don't know.  So,
>> I want to add the filename to the debug message.
>>
>> The lines in gdcm are:
>>
>>   if( !reader.Read() )
>>     {
>>       //added more detail for those instances where you can't debug, like
>> in java
>>       std::string theFilename(filename);
>>       std::string theError = "ImageReader failed on file: " + theFilename;
>>       vtkErrorMacro( theError );
>>       return 0;
>>     }
>>
>> and they were:
>>
>>   if( !reader.Read() )
>>     {
>>       vtkErrorMacro( "ImageReader failed" );
>>       return 0;
>>     }
>>
>> I don't want to change vtk at all, I want to use what exists.  I could
>> just modify my version right now to make my error message work (or at least
>> compile)-- but how should I use the warning/error macros to get more
>> information out than just a pure const char*?  I tried to use
>> theError.c_str(), but that also failed.  It also failed to compile if I just
>> sent filename over directly, as in vtkErrorMacro(filename);
>>
>> Thanks,
>> Mark
>>
>>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101122/5c3e5b30/attachment.htm>


More information about the vtkusers mailing list