Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having layered architecture in my project I am looking for an approach to avoid throwing exception between layers as throwing exceptions is associated with some cost always.

Is there any alternative approach for this.
Any help will be appreciated.
Posted

The only alternative is to return some sort of error status code. I do often use code like:

if (!DataLayer.Save(myObject) // If it fails, tell the user it failed.
 
Share this answer
 
From the requirement you are asking, you can just remove try/catch at any layer other than UI (Automatic throw). Directly catch it in presentation layer and accordingly display it.

Though it's not suggested for 'all' scenario's. One should put it based on the need.

Further, i read a convincing article long back....
The True Cost of Exceptions[^]

Try-catch at every place is still not suggested but should not be avoided in the places where it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900