Hello,
I am trying to find some documentation on how to programatically handle
errors. 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.
Is there some documents on this? 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.