On Tue, Nov 15, 2016 at 8:16 PM yann19 <[email protected]> wrote:

> Hi Justin, thanks for getting back!
> Earlier you have mentioned that in those two functions I have, raising
> Exception is not ideal. In that case, will it do any better if I used
> IOError within the init function and use that instead?
>

Raising an exception in itself is fine. I was specifically saying that the
base Exception is not very descriptive. You should try and use the most
specific builtin Exception type that matches your issue, as defined in:
https://docs.python.org/2/library/exceptions.html

If your error really is related to filesystem input/output issues, then
maybe IOError is ok, but it won't make much sense to the caller who doesn't
know too much about the implementation of your dialog. Maybe it is better
to not perform filesystem operations from within a constructor of a class,
and defer those for when your dialog is being shown? If you know the type
parameter is wrong right away, you can raise the TypeError or ValueError.
But if its a good value, then you could just raise the IOError at a later
point when it is shown. Or maybe you don't raise and you choose to display
nothing and to log the error instead of failing.


>
> Also, a rather noob question from me. While before I do or know any
> handling, if I try to 'break' my code, I can know what error to use, eg.
> valueerror etc.
> But as there are times such traceback error is not shown , using my
> scenario, if type is an empty string, I do not know which to use as it
> prompt of no such error type. How do I know which is the correct to use?
> I use ioerror, did some trial and error, seems to work and hence did not
> thought much of it..
>

When doing exception handling, you should know the types of exceptions that
can be raised either from knowing explicitly what kind of operations you
are doing (such as file system operations) or via the documentation of the
functions you are calling that tell you what possible exceptions can be
raised. Of course exceptions, being exceptions, can be raised unexpectedly.
And once you find those problems you should either fix a bug or catch and
handle that now expected exception type.


>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/89048a7a-3b28-406f-b9a0-b343fe3d2279%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1BEEL%3DCKOx8mEC5NyJggasVYofTrNb1KSFsDJe_KhW8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to