c# - Error handling: Exceptions vs Error method -
i'm creating 3-tier app , have problem dealing error handling. don't know if should throw exception or call method communicate problem other layers.
here quick exemple, have:
- filechooserframe
(presentation tier) allow user select file in list.
- datahandler
(app tier) stuff path of file , link between presentation & data tier.
- fileparser
(data tier) parse file , data it.
now let file must follow special structure, , if it's not, want show messagebox.
i'm not able know if user selected file before parsing it.
my question is, do when see file isn't following structure ?
thought 2 things:
1 - stop current action , call method in datahandler
(ex. notifywrongfileerr()
) that'll ask frame show messagebox.
2 - throw custom exception catch in filechooserframe
that'll show pop-up.
both of case have pros/cons can't choose between them. appropriate thing ?
ps: in case n°2, write exception class ? in file dedicated app's exceptions, or next class that'll throw ?
well it's choice, best practise exceptions throw exceptions under circumstances didn't expect. since expecting person able select invalid file name, calling method may considered "best practise". again, there no right or wrong , long happy it. if me create set of data tier exceptions things , throw them, way if ever wanted test data teir using test code (ioc) see exceptions.
Comments
Post a Comment