octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opinions: exceptions in user oct files


From: Mike Miller
Subject: Re: Opinions: exceptions in user oct files
Date: Tue, 2 May 2017 19:35:32 -0700
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, May 02, 2017 at 15:06:25 -0400, John W. Eaton wrote:
> On 05/02/2017 03:07 AM, Olaf Till wrote:
> > On Mon, May 01, 2017 at 01:39:22PM -0700, Mike Miller wrote:
> > >  - Should Octave catch any unknown exception object and turn it into a
> > >    general error message, preventing the interpreter from a hard exit?
> > > 
> > >  - Or should Octave require that user code not throw any exceptions
> > >    other than the ones that Octave knows how to handle?
> > 
> > I think the latter is better, maybe with the addition that Octave
> > attempts a core dump.
> > 
> > The thing is that Octave doesn't know the consequences of the cause
> > for the uncaught exception in user code. If one of the consequences
> > is, e.g., a memory leak, the faulty user code could eat up the memory
> > if called in a loop with try-catch.

Hmm, I'm not sure I agree that the situation is as dire as that. I
expect user code that uses and works with exceptions to be a bit more
well behaved. If an exception is not caught, the stack should unwind and
clean up after itself, Octave will report the error, and execution
should be able to continue normally.

If the user code is indeed faulty and uses bare pointers unsafely,
forgets about allocated memory, or other bad programming practices, that
could eventually lead to memory corruption or overrun, which should
result in a SIGSEGV or SIGBUS. This situation is the same whether
exceptions are involved or not. At that point Octave will handle these
signals the same way it does now, attempt to save the workspace and
exit. I'm not proposing any change to that behavior.

> I don't see that it's any worse than an immediate crash because of an
> unhandled exception.
> 
> If I understand correctly, Mike was suggesting a generic catch block at the
> top level, which would then issue an error message and return to the command
> prompt.  At that point one could choose to continue or exit. The error
> message might say something like "Octave encountered an unknown exception.
> This may be a bug in an external library, or in Octave itself.  You may wish
> to save your work and restart Octave."

Yes, that is what I meant. And maybe even a special case for any
std::exception, which is guaranteed to have a what() method that might
help describe the reason.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]