c# - If a function expects a return value, but inside the function i catch an error and want to break out -



c# - If a function expects a return value, but inside the function i catch an error and want to break out -

if function expects homecoming value, within function grab error , want break out of function, how do in c#... issue (feel free skip commented lines):

public static async task<string> getdata(string url, string props = "") { string query = url + "?oauth_token=" + contract.access_token + props; httpwebrequest request = (httpwebrequest)webrequest.create(apiurl + query); request.headers[httprequestheader.ifmodifiedsince] = datetime.now.tostring(); request.method = httpmethod.get; seek { httpwebresponse response = (httpwebresponse)await request.getresponseasync(); debug.writeline(response.contenttype); system.io.stream responsestream = response.getresponsestream(); string data; using (var reader = new system.io.streamreader(responsestream)) { info = reader.readtoend(); } responsestream.close(); apierror error = new apierror (); seek { using (memorystream stream = new memorystream(encoding.utf8.getbytes(data))) { datacontractjsonserializer serializer = new datacontractjsonserializer(typeof(apierror )); error = (apierror )serializer.readobject(stream); } messagebox.show(error.error_description); homecoming null; // want break out here, don't want application go on thread... there way of doing without having go , code controller model calls seek , catch? } grab (exception e) { homecoming data; // api did not homecoming error go on normal } } grab (exception ex) { var = ex.innerexception webexception; if (we != null) { var resp = we.response httpwebresponse; var code = resp.statuscode; messagebox.show("respcallback exception raised! message:{0}" + we.message); debug.writeline("status:{0}", we.status); homecoming we.message; } else throw; } }

don't grab exception.

leave exception caught caller - or, optionally grab , wrap in own exception type.

you're putting of eggs in 1 basket here - catching far downwards leaves little wiggle room. letting bubble gives more options handling it.

c#

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -