I have a code that gets a Product
object from a web service. If there is no product, it returns an EntityDoesNotExist
exception. I need to handle this.. However, I have a lot of other code that deals with the returned Product
, but if this code is not within the try/catch, it doesn't work because Product
is basically not defined. Is the only way to make this work to include my other related code within the try/catch? This seems really sloppy.
Code example:
try {
Product product = catalogContext.GetProduct("CatalogName", "ProductId");
} catch(EntityDoesNotExist e) {
// Do something here
}
if(dataGridView1.InvokeRequired) {
// Do something in another thread with product
}