Hi Rob,

Alas,  I didn't write the pdf library.  I've interspersed my comments below.
> John Dammeyer wrote:
> > I'm printing out using a pdf library that is throwing an exception.
> > 
> > Type 
> >    PDFException = Exception;
> 
> That makes PDFException an alias for Exception. It will be 
> better if you 
> define the one as a descendant of the other.
> 
> type
>    EPDFException = class(Exception);

Unfortunately I can't do that without rewriting the library code.


> 
> Look at the declarations in SysUtils for more examples.
> 
> > Then in the code...
> > 
> > raise PDFException.Create('Error in BeginDoc!');
> 
> The first thing I'd wonder, when I saw an error message like that, is 
> what kind of error? Can your code be any more specific about 
> what went 
> wrong?
> 
> > Except the text is 'Invalid Filename' which I can't find in 
> the source.
> 
> So, you're raising an exception, but the text isn't what you 
> told it to be?

No I'm not raising the exception, the library is.  And that's the problem.  

> 
> > My application is doing a 
> > 
> >   try
> >     PDFPrinter.BeginDoc;
> >   except
> >    MessageDlg(
> >         'Can''t print "'+SummaryFileName+
> >         '" to Memory Dongle -- Make sure there is file space and try
> > again.',
> >         mtConfirmation,
> >         [mbOK],
> >         0);
> 
> You're showing a dialog box in response to an exception without any 
> knowledge of what the exception is. Never do that. Always catch a 
> specific type of exception, and let the ones you aren't prepared to 
> handle propagate up the stack to something that is prepared 
> to handle them.

The 'Invalid Filename' comes when I don't handle any.  In other words, I get
rid of the try..except..end and just call PDFPrinter.BeginDoc.  The problem
is for the end user, 'Invalid Filename' is also (for them) a garbage message
that they have no ability to change or do something about.  In the field,
the only reason the message would appear is if the memory stick dongle
plugged into the USB is not there or full.  So my message is normally fine.

But this application is now running on a desktop and I think, the location
they are trying to write the pdf file to doesn't have write permission.
Which makes 'Invalid Filename' sort of correct but doesn't tell the user
anything.

> 
> except
>    on E: EPDFException do begin
>      // ...
>    end;
> end;
> 
> That will catch only PDF exceptions.
> 

Tried that.  Didn't work.  Hence my question.  I used PDFException which was
supposed to be an alias for Exception.  

> All descendants of Exception have a Message parameter, which 
> holds the 
> string passed to the exception when it was constructed.
> 

I'll do some more digging.  Thanks

John

> -- 
> Rob
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
> 
> 

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to