Discussion:
OnError [Thread"::"tdlen"]
(too old to reply)
EMartin
2014-04-11 06:12:19 UTC
Permalink
Hi,

Many classic programming languages provide a command to interrupt
computations when some exception arises, allowing to perform any action on
the exception as in something as, for example:

OnError [] do (action)] [routine] (*This could be the general pattern*)

OnError [] do (Print[Stack]; Abort[] ) [routine] (*This could be a more
specific pattern*)

OnError [Thread"::"tdlen"] do JumpToCheck ][routine]

(*The above could be a more specific but even more general pattern. The jump
made to an exception handling routine to evaluate or treat the exception*)



These catching commands should be located at the beginning of the whole
code as in *TimeConstrained[routine, time]* which aborts the routine if it
takes more than time seconds.



Mathematica has got enough stuff to deal with erroneous situation (Abort,
Interrupt, Catch, Throw,=85) provided one is able to catch the exception (and
its type) as soon as it arises , but I never was able to do it.



Since Mathematica prints the errors messages, the type of the exception and
the exact point where it arises is available (but hidden) to let the user to
take control. Probably the tool is already available but I can find it.



Any help will be welcome



E. Martin-Serrano

__________________________________________

This e-mail and the documents attached are confidential and intended solely
for the addressee; it may also be privileged. If you receive this e-mail in
error, please notify the sender immediately and destroy it. As its integrity
cannot be secured on the Internet, no sender92s liability can be = triggered
for the message content. Although the sender endeavors to maintain a
computer virus-free network, he/she does not warrant that this transmission
is virus-free and will not be liable for any damages resulting from any
virus transmitted.

Este mensaje y los ficheros adjuntos pueden contener informaciF3nconfidencial destinada solamente a la(s) persona(s) mencionadas
anteriormente y su contenido puede estar protegido por secreto profesional y
en cualquier caso el mensaje en su totalidad est=E1 amparado y protegido por
la legislaci=F3n vigente que preserva el secreto de las comunicaciones, y por
la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. Si usted recibe
este correo electr=F3nico por error, gracias por informar inmediatamente al
remitente y destruir el mensaje. Al no estar asegurada la integridad de este
mensaje sobre la red, el remitente no se hace responsable por su contenido.
Su contenido no constituye ning=FAn compromiso para el remitente, salvo
ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al m=E1ximo por
mantener su red libre de virus, el emisor no puede garantizar nada al
respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan resultar de
una transmisi=F3n de virus.
Bob Hanlon
2014-04-12 09:16:53 UTC
Permalink
"Check[expr, failexpr] evaluates expr, and returns the result, unless
messages were generated, in which case it evaluates and returns failexpr. "


Bob Hanlon
Post by EMartin
Hi,
Many classic programming languages provide a command to interrupt
computations when some exception arises, allowing to perform any action on
OnError [] do (action)] [routine] (*This could be the general pattern*)
OnError [] do (Print[Stack]; Abort[] ) [routine] (*This could be a more
specific pattern*)
OnError [Thread"::"tdlen"] do JumpToCheck ][routine]
(*The above could be a more specific but even more general pattern. The
jump
made to an exception handling routine to evaluate or treat the exception*)
These catching commands should be located at the beginning of the whole
code as in *TimeConstrained[routine, time]* which aborts the routine if it
takes more than time seconds.
Mathematica has got enough stuff to deal with erroneous situation (Abort,
Interrupt, Catch, Throw,=85) provided one is able to catch the exception
(and
its type) as soon as it arises , but I never was able to do it.
Since Mathematica prints the errors messages, the type of the exception and
the exact point where it arises is available (but hidden) to let the user
to
take control. Probably the tool is already available but I can find it.
Any help will be welcome
E. Martin-Serrano
__________________________________________
This e-mail and the documents attached are confidential and intended solely
for the addressee; it may also be privileged. If you receive this e-mail in
error, please notify the sender immediately and destroy it. As its
integrity
cannot be secured on the Internet, no sender92s liability can be =
triggered
for the message content. Although the sender endeavors to maintain a
computer virus-free network, he/she does not warrant that this
transmission
is virus-free and will not be liable for any damages resulting from any
virus transmitted.
Este mensaje y los ficheros adjuntos pueden contener
informaciF3nconfidencial destinada solamente a la(s) persona(s) mencionadas
anteriormente y su contenido puede estar protegido por secreto profesional
y
en cualquier caso el mensaje en su totalidad est=E1 amparado y protegido
por
la legislaci=F3n vigente que preserva el secreto de las comunicaciones, y
por
la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. Si usted
recibe
este correo electr=F3nico por error, gracias por informar inmediatamente
al
remitente y destruir el mensaje. Al no estar asegurada la integridad de
este
mensaje sobre la red, el remitente no se hace responsable por su contenido.
Su contenido no constituye ning=FAn compromiso para el remitente, salvo
ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al m=E1ximo
por
mantener su red libre de virus, el emisor no puede garantizar nada al
respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan
resultar de
una transmisi=F3n de virus.
EMartin
2014-04-23 08:51:50 UTC
Permalink
Hi Bob,

Thanks for your answer but 'Check' does not work as I expected, or I do not
understand the cryptic direction in the help.

"Check[expr, failexpr] evaluates 'expr', and returns the result (of expr),
unless messages were generated, in which case it evaluates 'failexpr' and
returns the result of the evaluation of 'failexpr'. "

I tried so but I failed in dumpping the Stack[] contents, that I attempted.

The key point is that Mathematica should return (or empowered the programmer
to handle) the whole context where an error is produced, note that the 'line
number' which sometimes appears in the messages raised by the system is
unreachable in practical terms for average users like me (or at least to
costly); it is one of those Mathematica arcane. Is there any facility to, at
least, get such line numbers?

As an example of the problem I am facing to bring to work a great deal of my
'old' pieces of software, years ago (maybe ten), I wrote, and submitted to
Mathgroup, a routine to catch improper function calls (calls with faulty
actual parameters). It was not about catching the point where the error
comes up but about why the error takes place due to a function call with
data generated somewhere else. The routine damped the Stack[] to help in
rebuilding the whole context as to do some sort of forensic analysis since
the source of the error can be truly far away from the point where the
conflict is discovered.

But thanks again Bob

E. Martin-Serrano


De: Bob Hanlon [mailto:***@gmail.com]
Enviado el: viernes, 11 de abril de 2014 15:34
Para: EMartin
CC: MathGroup
Asunto: Re: OnError [Thread"::"tdlen"]

"Check[expr, failexpr] evaluates expr, and returns the result, unless
messages were generated, in which case it evaluates and returns failexpr. "

Bob Hanlon

On Fri, Apr 11, 2014 at 2:12 AM, EMartin <***@telefonica.net
<mailto:***@telefonica.net> > wrote:

Hi,

Many classic programming languages provide a command to interrupt
computations when some exception arises, allowing to perform any action on
the exception as in something as, for example:

OnError [] do (action)] [routine] (*This could be the general pattern*)

OnError [] do (Print[Stack]; Abort[] ) [routine] (*This could be a more
specific pattern*)

OnError [Thread"::"tdlen"] do JumpToCheck ][routine]

(*The above could be a more specific but even more general pattern. The jump
made to an exception handling routine to evaluate or treat the exception*)

These catching commands should be located at the beginning of the whole
code as in *TimeConstrained[routine, time]* which aborts the routine if it
takes more than time seconds.

Mathematica has got enough stuff to deal with erroneous situation (Abort,
Interrupt, Catch, Throw,=85) provided one is able to catch the exception
(and
its type) as soon as it arises , but I never was able to do it.

Since Mathematica prints the errors messages, the type of the exception and
the exact point where it arises is available (but hidden) to let the user to
take control. Probably the tool is already available but I can find it.



Any help will be welcome



E. Martin-Serrano

__________________________________________

This e-mail and the documents attached are confidential and intended solely
for the addressee; it may also be privileged. If you receive this e-mail in
error, please notify the sender immediately and destroy it. As its integrity
cannot be secured on the Internet, no sender92s liability can be = triggered
for the message content. Although the sender endeavors to maintain a
computer virus-free network, he/she does not warrant that this transmission
is virus-free and will not be liable for any damages resulting from any
virus transmitted.

Este mensaje y los ficheros adjuntos pueden contener
informaciF3nconfidencial destinada solamente a la(s) persona(s) mencionadas
anteriormente y su contenido puede estar protegido por secreto profesional y
en cualquier caso el mensaje en su totalidad est=E1 amparado y protegido
por
la legislaci=F3n vigente que preserva el secreto de las comunicaciones, y
por
la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. Si usted
recibe
este correo electr=F3nico por error, gracias por informar inmediatamente al
remitente y destruir el mensaje. Al no estar asegurada la integridad de este
mensaje sobre la red, el remitente no se hace responsable por su contenido.
Su contenido no constituye ning=FAn compromiso para el remitente, salvo
ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al m=E1ximo por
mantener su red libre de virus, el emisor no puede garantizar nada al
respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan resultar
de
una transmisi=F3n de virus.
Bob Hanlon
2014-04-23 08:53:13 UTC
Permalink
For your function define one or more messages for bad arguments. For
example,


ClearAll[factorial]


factorial::niarg = "The argument `1` cannot be a negative integer.";


Define your function to issue a message and return unevaluated upon an
error :


factorial[n_]/;If[

TrueQ[!NumericQ[n]||!(Element[n,Integers]&&n<0)],

True, Message[factorial::niarg,n]; False] :=

n!


BesselI[0,factorial[-1]]


factorial::niarg: The argument -1 cannot be a negative integer.


BesselI[0,factorial[-1]]


Use Check to do something other than return unevaluated (e.g., Abort) when
message is generated


Check[BesselI[0,factorial[-1]],Abort[]]


factorial::niarg: The argument -1 cannot be a negative integer.


$Aborted


PDF[NormalDistribution[m,0],x]


NormalDistribution::posprm: Parameter 0 at position 2 in
NormalDistribution[m,0] is expected to be positive. >>


PDF[NormalDistribution[m,0],x]


Check[PDF[NormalDistribution[m,0],x],Abort[]]


NormalDistribution::posprm: Parameter 0 at position 2 in
NormalDistribution[m,0] is expected to be positive. >>


$Aborted



Bob Hanlon
Post by EMartin
Hi Bob,
Thanks for your answer but =E2=80=98Check=E2=80=99 does not work as I exp=
ected, or I do
Post by EMartin
not understand the cryptic direction in the help.
"Check[expr, failexpr] evaluates =E2=80=98expr=E2=80=99, and returns the =
result (of expr),
Post by EMartin
unless messages were generated, in which case it evaluates =E2=80=98faile=
xpr=E2=80=99 and
Post by EMartin
returns the result of the evaluation of =E2=80=98failexpr=E2=80=99. "
I tried so but I failed in dumpping the Stack[] contents, that I attempte=
d.
Post by EMartin
The key point is that Mathematica should return (or empowered the
programmer to handle) the whole context where an error is produced, note
that the =E2=80=98line number=E2=80=99 which sometimes appears in the mes=
sages raised by
Post by EMartin
the system is unreachable in practical terms for average users like me (o=
r
Post by EMartin
at least to costly); it is one of those Mathematica arcane. Is there any
facility to, at least, get such line numbers?
As an example of the problem I am facing to bring to work a great deal of
my =E2=80=98old=E2=80=99 pieces of software, years ago (maybe ten), I wro=
te, and submitted
Post by EMartin
to Mathgroup, a routine to catch improper function calls (calls with
faulty actual parameters). It was not about catching the point where the
error comes up but about why the error takes place due to a function call
with data generated somewhere else. The routine damped the Stack[] to he=
lp
Post by EMartin
in rebuilding the whole context as to do some sort of forensic analysis
since the source of the error can be truly far away from the point where
the conflict is discovered.
But thanks again Bob
E. Martin-Serrano
*Enviado el:* viernes, 11 de abril de 2014 15:34
*Para:* EMartin
*CC:* MathGroup
*Asunto:* Re: OnError [Thread"::"tdlen"]
"Check[expr, failexpr] evaluates expr, and returns the result, unless
messages were generated, in which case it evaluates and returns failexpr.=
"
Post by EMartin
Bob Hanlon
Hi,
Many classic programming languages provide a command to interrupt
computations when some exception arises, allowing to perform any action o=
n
Post by EMartin
OnError [] do (action)] [routine] (*This could be the general pattern*)
OnError [] do (Print[Stack]; Abort[] ) [routine] (*This could be a more
specific pattern*)
OnError [Thread"::"tdlen"] do JumpToCheck ][routine]
(*The above could be a more specific but even more general pattern. The
jump
made to an exception handling routine to evaluate or treat the exception*=
)
Post by EMartin
These catching commands should be located at the beginning of the whole
code as in *TimeConstrained[routine, time]* which aborts the routine if =
it
Post by EMartin
takes more than time seconds.
Mathematica has got enough stuff to deal with erroneous situation (Abort,
Interrupt, Catch, Throw,=85) provided one is able to catch the exceptio=
n
Post by EMartin
(and
its type) as soon as it arises , but I never was able to do it.
Since Mathematica prints the errors messages, the type of the exception a=
nd
Post by EMartin
the exact point where it arises is available (but hidden) to let the user
to
take control. Probably the tool is already available but I can find it.
Any help will be welcome
E. Martin-Serrano
__________________________________________
This e-mail and the documents attached are confidential and intended sole=
ly
Post by EMartin
for the addressee; it may also be privileged. If you receive this e-mail =
in
Post by EMartin
error, please notify the sender immediately and destroy it. As its
integrity
cannot be secured on the Internet, no sender92s liability can be =
triggered
for the message content. Although the sender endeavors to maintain a
computer virus-free network, he/she does not warrant that this
transmission
is virus-free and will not be liable for any damages resulting from any
virus transmitted.
Este mensaje y los ficheros adjuntos pueden contener
informaciF3nconfidencial destinada solamente a la(s) persona(s) mencionad=
as
Post by EMartin
anteriormente y su contenido puede estar protegido por secreto profesiona=
l
Post by EMartin
y
en cualquier caso el mensaje en su totalidad est=E1 amparado y protegi=
do
Post by EMartin
por
la legislaci=F3n vigente que preserva el secreto de las comunicaciones,=
y
Post by EMartin
por
la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. S=
i usted
Post by EMartin
recibe
este correo electr=F3nico por error, gracias por informar inmediatamen=
te
Post by EMartin
al
remitente y destruir el mensaje. Al no estar asegurada la integridad de
este
mensaje sobre la red, el remitente no se hace responsable por su contenid=
o.
Post by EMartin
Su contenido no constituye ning=FAn compromiso para el remitente, salv=
o
Post by EMartin
ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al m=E1x=
imo
Post by EMartin
por
mantener su red libre de virus, el emisor no puede garantizar nada al
respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan
resultar de
una transmisi=F3n de virus.
Loading...