c# - Debugging exception through multiple nested async calls -


per answer this question, form capturing exception thrown asynchronous method looks this:

public async void dofoo() {     try     {         await foo();     }     catch (protocolexception ex)     {           /* exception caught because you've awaited call. */     } } 

great. seems disintegrate if want bubble several levels of asynchrony though. here's exception originates:

internal static async task makepdfpagesfrompdf(pdf pdf, byte[] pdfbytes, int jobid) {     ienumerable<image> pdfasimages = pdfoperations.pdftoimagespdfium(pdfbytes, dpi);      if(pdfasimages.count() < 1)     {         throw new argumentexception("pdf has no pages.");     }      // ... more code ... } 

here's method calls makepdfpagesfrompdf:

internal static async task processbase64pdf(pdf pdf, int jobid, string componentdesignname) {     byte[] pdfbytes = convertbase64topdfbytearray(pdf.url); // base64 data in pdf.url     await uploadpdftoawss3(pdf, pdfbytes, jobid, componentdesignname);     try     {         await makepdfpagesfrompdf(pdf, pdfbytes, jobid);     }     catch(argumentexception argumentexception)     {         throw argumentexception;     } } 

i catch exception in example cited @ beginning of question. debugging asserts catch block hit. however, need bubble exception 1 more level, inside controller route:

try {     await pdfscontroller.processbase64pdf(pdf, componentdesign.jobid, componentdesign.name); } catch (argumentexception argumentexception) {     // stuff exception                   } 

it doesn't hit highest level catch @ breakpoint. removing intermediate catch has no effect. route continues , returns, not able hit breakpoints after argumentexception thrown intermediate catch. what's going on here , how can hit breakpoints through whole asynchronous stack?

if method want propogate exception async void (such in example of dofoo), issue there no task object propagate exception (since method void , not return task)

another thing suggest not throw argumentexception, rather throw, former loses call stack of original exception


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -