I am currently loading images in various ways like this:
Try {// path 1} hold {// path 1 did not try {// path 2} hold {// etc}}
I was wondering what to do There was a cleaner way to do this. This is not a problem at present, but if I add some more ways that it will get messy.
Note that the method of loading the image is also in the same way as it is not an image.
It is basically trying a bunch of stuff to find out what you dragged into the application.
You write a method that accepts delegates in any number, trying all of them And to stop any of them after successfully running it controls the exception in one place, and avoids all recurrence:
public static zero AttemptAll (parameter action [] verb) {Var exception = new list & lt; Exceptions & gt; (); Forrest (action in action) (attempt {action}; return;} catch (exception e) {add exception (e);}} throwing new aggregate exception (exception);}
This allows you to write:
Effort (attempts 1, attempt 2, attempt 3);
If methods calculate any result You can also create a second overload to handle it:
Public Static T Attempts are all done (params Func & lt; T & gt; [] Verbs) {var up Prahlad = new List & lt; exception & gt; (); foreign (different verb verb) {try {return action ())} catch (Exception e) {exception. Add (e); }} Throwing new aggregate exceptions (exceptions); }
Comments
Post a Comment