Question: exception using solve. How to catch when using assertlevel?

I am getting an exception divide by zero using solve. The problem is that when using kernelopts('assertlevel'=2):  I am no longer able to catch the exception in a catch try.

Removing kernelopts('assertlevel'=2):  I can catch the exception.

But I need to use kernelopts('assertlevel'=2): in my program.   

Is there a way to keep kernelopts('assertlevel'=2): and still catch exception thrown by solve?

Is this a bug in solve? And why using kernelopts('assertlevel'=2): prevents catching the exception?

Using Maple 2021.2 on windows 10. Worksheet attached.

 exception generated

 

 

restart;

trial_solution_constants:=[A[1]];
eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
solve(identity(eq,x),trial_solution_constants)

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

Error, (in unknown) numeric exception: division by zero

Using assertlevel, now unable to catch exception

 

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2):

3

try
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
   solve(identity(eq,x),trial_solution_constants)
catch:
   print("error happend ",lastexception);
end try;
print(" I am here");

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

Error, (in unknown) assertion failed

" I am here"

Not Using assertlevel now can catch exception

 

restart;

interface(warnlevel=4);

3

try
   trial_solution_constants:=[A[1]];
   eq:=-A[1]-exp(x^2)*exp(-x^2) = 0;
   solve(identity(eq,x),trial_solution_constants)
catch:
   print("error happend ",lastexception);
end try;
print(" I am here");

[A[1]]

-A[1]-exp(x^2)*exp(-x^2) = 0

"error happend ", unknown, "numeric exception: division by zero"

" I am here"

 

Download march_8_2021_solve.mw

 

Update Sept 7,2022

FYI, here is another internal exception generated by solve which shows only when kernelopts('assertlevel'=2): is set, and which can not be trapped using try/catch. May be this could be fixed in future version of Maple. 

Worksheet attached.


 

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1314 and is the same as the version installed in this computer, created 2022, September 2, 15:54 hours Pacific Time.`

restart;

inter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*exp(X*y0)*exp(x0*Y)*exp(x0*y0)*y0+1)/(exp(X*Y)*exp(X*y0)*exp(x0*Y)*exp(x0*y0)*X+exp(X*Y)*exp(X*y0)*exp(x0*Y)*exp(x0*y0)*x0+2*Y+2*y0)^2*(X^2*exp(X*Y)*exp(X*y0)*exp(x0*Y)*exp(x0*y0)+2*exp(X*Y)*exp(X*y0)*x0*exp(x0*Y)*exp(x0*y0)*X+exp(X*Y)*exp(X*y0)*x0^2*exp(x0*Y)*exp(x0*y0)+2)):


try
     sol:=solve(identity(eq,X),[x0, y0]);
catch:
     print("exception");
end try;

Error, (in unknown) assertion failed

 


 

Download solve_exception.mw

 

 

 

Please Wait...