简体   繁体   中英

3 layers(Projects): How can I throw an exception from first layer and catch it in the third

I have three layers:

  1. ServiceHandlers ( which talks to the ax2012 and maps the data to entity)
  2. Services ( Which calls the functions from serviceHandlers such as getOrder and returns it)
  3. Winform(or could be whatever for someone to design the UI, uses the services logic to do so).

My problem is the exception handling in the ServiceHandlers. I implemented my own exception could EntityNotFound which i throw when the getEntity functions is called and doesnt find anything. What i do when i catch it is throw it again and catch it in Services.

Inside the catch block there i only use the statement throw; .. which i though would just throw it back again and then i was gonna catch in the catch statement in the winform layer. But what happens is that application stops in services layer and says "EntityNotFoundException" was unhandled which is okai but i want that to happen in the winform layer.

Hope this is understandable , so .. are there any suggestions ?

First off, Unless you are adding some value such as logging, or adding costume messages don't catch and rethrow exceptions. You can try ... catch the exception in the GUI layer to handle it there appropriately.

Second, a sample code would help to help you debugging the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM