<html aria-label="message body"><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">No. Your callback function should not be returning a PETSC_ERR_NOT_CONVERGED since your function doesn't know anything about the status of the nonlinear solver and is not in the business of deciding if SNES is converging or not.<div><br></div><div>What are you trying to convey back to PETSc if your function is not "all good"?</div><div><br></div><div>There are generally two possibilities,</div><div><br></div><div>1) just give up and stop the entire program immediately, then return PETSC_ERR_USER</div><div><br></div><div>2) indicate that SNES solve is asking your function to be evaluated at a point that is not in the domain of your function. For example, say your function is the square root and x is -1. In this situation, depending on the exact nonlinear solver being used SNES may be able to continue to try to solve the nonlinear system by changing its x value.  To indicate this call SNESSetFunctionDomainError(snes); and then do a usual return PETSC_SUCCESS; If SNES can continue it will, if it cannot then IT will generate a negative SNESConvergedReason indicating that SNES did not converge.</div><div><br></div><div>Barry</div><div><br></div><div><br></div><div><br><div><br></div><div><br><div><font face="Monaco" size="1"><br></font></div><div><font face="Monaco" size="1"><br id="lineBreakAtBeginningOfMessage"></font><div><br><blockquote type="cite"><div>On Oct 1, 2025, at 11:46 AM, Zou, Ling via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Although I haven’t tried yet. Does it make sense and should it work to change the code this way?<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">PetscErrorCode SNESFormFunction(SNES, Vec, Vec, void*);</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">double my_function();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">double my_function()</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  if (all_good)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">return 1;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  else</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">throw 199;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">return 0;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">PetscErrorCode SNESFormFunction(SNES snes, Vec u, Vec r, void* ctx)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  Try<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">my_value = my_function();<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  Catch (int err)<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">    return PETSC_ERR_NOT_CONVERGED;<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  // compute residuals<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  return PETSC_SUCCESS;<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">int main(int argc, char **argv)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  Initialize_PETSc();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  double dt = 1, dt_min = 0.001;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  while (dt > dt_min)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">SNESSolve(AppCtx.snes, NULL, AppCtx.u);<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">SNESGetConvergedReason(AppCtx.snes, &(AppCtx.snes_converged_reason));<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">if (not_converged)<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">  dt *= 0.5;<o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  PetscFinalize();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"><o:p> </o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"><o:p> </o:p></span></div><div id="mail-editor-reference-message-container"><div><div><div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) currentcolor currentcolor; border-image: none; padding: 3pt 0in 0in;"><p class="MsoNormal" style="margin: 0in 0in 12pt; font-size: 10pt; font-family: Aptos, sans-serif;"><b><span style="font-size: 12pt;">From:<span class="Apple-converted-space"> </span></span></b><span style="font-size: 12pt;">petsc-users <<a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Zou, Ling via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br><b>Date:<span class="Apple-converted-space"> </span></b>Wednesday, October 1, 2025 at 9:33</span><span style="font-size: 12pt; font-family: Arial, sans-serif;"> </span><span style="font-size: 12pt;">AM<br><b>To:<span class="Apple-converted-space"> </span></b>PETSc <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br><b>Subject:<span class="Apple-converted-space"> </span></b>[petsc-users] Proper way for exception handling<o:p></o:p></span></p></div><div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Hi,</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">After updating to PETSc 3.23 (from a quite old version, ~3.8), I found that my old way of exception handling not working any more, on my Mac.</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">I would like to learn the proper way to handle exceptions in PETSc code.</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Here is my pseudo code:</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">PetscErrorCode SNESFormFunction(SNES, Vec, Vec, void*);</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">double my_function();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">double my_function()</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  if (all_good)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">return 1;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  else</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">throw 199;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">return 0;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">PetscErrorCode SNESFormFunction(SNES snes, Vec u, Vec r, void* ctx)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  double my_value = my_function();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  // compute residuals</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">int main(int argc, char **argv)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  Initialize_PETSc();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  double dt = 1, dt_min = 0.001;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  while (dt > dt_min)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  {</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">try</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">  SNESSolve(AppCtx.snes, NULL, AppCtx.u);</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">catch (int err)</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">{</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">  dt *= 0.5;</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif; text-indent: 19.5pt;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  }</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">  PetscFinalize();</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">}</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 8pt; font-family: Monaco;">================================================================</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">This piece of logic used to work well, but now giving me the following error:</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Current time (the starting time of this time step) = 0.. </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">        NL step =  0, SNES Function norm =  8.60984E+03</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt; background: yellow;">libc++abi: terminating due to uncaught exception of type int</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt; background: yellow;">Abort trap: 6</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Q1: why this exception catch logic not working any more?</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Q2: is there any good example of PETSc exception handling I can follow?</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;"> </span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">Best,</span><span style="font-size: 12pt;"><o:p></o:p></span></div><div style="margin: 0in; font-size: 10pt; font-family: Aptos, sans-serif;"><span style="font-size: 11pt;">-Ling</span></div></div></div></div></div></div></div></blockquote></div><br></div></div></div></body></html>