Scott,

Scott Purcell wrote:
> Hello,
> I am trying to find some documentation on how to programatically handle 
> errors. 
This is currently no option with Castor.

When using the (Un-)marshaller to go about data binding (for both
marshalling as well as unmarshalling), Castor simply collects the
exception(s) that occurred and throws them to indicate that something
went wrong.

Just out of curiosity, what would you be able to gain ? I mean, Castor
is (more or less) a complex state engine, and whenever the internal
state (e.g.l upon unmarshalling) is invalid, and exception will be
generated.


I am using the SourceGeneratorMain for now, which creates the java
> files and the descriptors (for validation?).
> 
> Anyway, I am intentially trying to break some of the "validation" rules, 
> ie. setting incorrect data and of course getting errors. Problem is, right 
> now, due to my lack of understanding, I am just throwing exceptions in my 
> main application.
> 
> Now I would like to be able to understand how I can control what errors 
> are occuring, and how I can show the errors as opposed to throwing them.
Well, like with any Java exceptions, most of these exception are checked
excpetions, so you will have to catch them anyhow. What's wrong about
building some logic around e.g. the invocation of the marshal() method
on the Marshaller object you are using that catches the exceptions being
(potentially) thrown, analyses them and prepares them for e.g. formatted
output ?

> Is there some documents on this? 
No, not really.

> or a link somewhere?
> 
> I was thinking you would call Marshall on the object, then ask for 
> something back like a errors object?. Not sure how this works.
> 
> Thanks
> Scott
> 
> // here is what I am doing now. How can I interrogate the errors this 
> produced. In this example, I set an invalid phone. It should be 
> \d{3}-\d{3}-\d{4}, but I left one off. This is my test. I would like to 
> pull back an object that would encapsulate the error as opposed to 
> throwing it.
> 
>    public static void main(String[] args) throws Exception {
>  
>  
>         Item item = new Item();
>         item.setQuantity(100000);
>         item.setId("1");
>         item.setInStock(false);
>         item.setCategory("my_category");
>         item.setPrice(new BigDecimal("100.00"));
>  
>         Address address = new Address();
>         address.setCity("my_city");
>         address.setState("MO");
>         address.setStreet1("76777777 mockingbird");
>         address.setStreet2("other street");
>         address.setZipCode("77779");
>  
>         Customer customer = new Customer();
>         customer.setName("Scott");
>         customer.setPhone("300-300-333");
>         customer.setAddress(address);
>  
>         ShipTo shipto = new ShipTo();
>         shipto.setCustomer(customer);
>  
>         ShippingMethod shipmethod = new ShippingMethod();
>         shipmethod.setCarrier("carrier");
>         shipmethod.setOption("UPS");
>         shipmethod.setEstimatedDelivery(new Duration("PT130S"));
>  
>         ShippingDate shipDate = new ShippingDate();
>         shipDate.setDate(new Date());
>         shipDate.setTime(new Time());
>  
>  
>         Invoice inv = new Invoice();
>         inv.setShippingMethod(shipmethod);
>         inv.setShipTo(shipto);
>         inv.setShippingDate(shipDate);
>         inv.addItem(item);
>  
>  
>         try {
>             FileWriter writer = new FileWriter("invoice.xml");
>             Marshaller.marshal(inv, writer);
>         } catch (Exception e) {
>             System.err.println(e.getMessage());
>             e.printStackTrace(System.err);
>         }
>     }
> 
> 
> 
> 
> CONFIDENTIALITY NOTICE
> This e-mail message and any attachments are only for the use of the intended 
> recipient and may contain information that is privileged, confidential or 
> exempt from disclosure under applicable law. If you are not the intended 
> recipient, any disclosure, distribution or other use of this e-mail message 
> or attachments is prohibited. If you have received this e-mail message in 
> error, please delete and notify the sender immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to