c# - Proper way to throw an error in a TPL Task so VS2012 does not complain -
i have founds threads similar not same forgive me if turns out duplicate. how 1 "throw" error inside task. have code , when conditions right throw error visual studio complains unhanded. afterwards performs should including _loaddatamappingfieldlisterror method. thought first continuewith suffice seems not. need create 2 separate tasks - 1 test , actual retrieval? seems little redundant. here code:
........ if (dcmapping.settingscomplete().isnullempty()) { _taskcanceller = new cancellationtokensource(); _taskloader = task<object>.factory.startnew(() => { //set indicator , first test connection make sure working isloadingdatamappingfieldlist = true; string test = dcmapping.testconnection(); if (test.isnotnullempty()) throw new dataconnectionexception(test); // <--the throw in question return dcmapping.getfieldnamelist(); // <--vs breaks here saying above unhandled }); //if there error _taskloader.continuewith( antecendant => _loaddatamappingfieldlisterror(antecendant.exception), _taskcanceller.token, taskcontinuationoptions.onlyonfaulted, taskscheduler.fromcurrentsynchronizationcontext()); //set receiving function _taskloader.continuewith( antecendant => _loaddatamappingfieldlistcomplete((list<string>)antecendant.result, remapfields), _taskcanceller.token, taskcontinuationoptions.notonfaulted, taskscheduler.fromcurrentsynchronizationcontext()); } ........
you have option "just code" turned on. in case, indicating exception is unhandled respect "just code". exception caught framework code , stored in task.
i, personally, recommend turning off "just code" setting tends in way more helps.
Comments
Post a Comment