Re: How can I handle validation exception?

From: Andrey Razumovsky (razumovsky.andre..mail.com)
Date: Thu Mar 12 2009 - 05:08:04 EDT

  • Next message: Andrus Adamchik: "Re: How can I handle validation exception?"

    At least in 3.0 ValidationException is runtime exception (extends
    CayenneRuntimeException), so no "throws" declaration is required! Anyways,
    if something's still wrong for you, you can try checking the type in catch
    block:

    catch(Exceprion ex) {
      if (ex instanceof ValidationException) {
        ...
      }
    }

    2009/3/12 <niparas..mail.com>

    > Maybe I didn't state it clearly. When I said:
    >
    > "The problem is that commitChanges() doesn't throw directly a
    > ValidationException so I cannot catch it in the catch block (it throws a
    > CayenneRuntimeException)"
    >
    > I meant that I can't write the following because it can't be compiled
    > (note that a ValidationException is caught):
    >
    > try {
    > context.commitChanges();
    > }
    > catch(ValidationException vex) {
    > // ...
    > }
    >
    > That is what I meant by saying "directly" (to be able to write
    > catch(ValidationException vex)).
    >
    > A ValidationException is thrown if there is a failure (so it is not a
    > bug). Sorry for confusing you.
    >
    > My question is: How can I get the validationResult inside the block
    > catch() if I write
    >
    > catch(Exception exc) {
    > // ...
    > }
    >
    > What is the suggested way of getting the failures produced during
    > validation?
    >
    > Nikos
    >
    > 12-03-2009, , 10:22 +0200, / Andrus Adamchik
    > :
    > > On Mar 12, 2009, at 9:41 AM, wrote:
    > >
    > > > The problem is that commitChanges() doesn't throw directly a
    > > > ValidationException so I cannot catch it in the catch block (it
    > > > throws a
    > > > CayenneRuntimeException)
    > >
    > > Which version of Cayenne? This could be a bug.
    > >
    > > Andrus
    > >
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Mar 12 2009 - 05:08:34 EDT