octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #64242] destructor is executed even if the con


From: Vipul Cariappa
Subject: [Octave-bug-tracker] [bug #64242] destructor is executed even if the constructor fails and throws an error
Date: Tue, 23 May 2023 10:50:33 -0400 (EDT)

URL:
  <https://savannah.gnu.org/bugs/?64242>

                 Summary: destructor is executed even if the constructor fails
and throws an error
                   Group: GNU Octave
               Submitter: vipul_cariappa
               Submitted: Tue 23 May 2023 02:50:31 PM UTC
                Category: Classdef
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Other
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: 8.2.0 8.X Series Bug Fix Release 
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 23 May 2023 02:50:31 PM UTC By: Vipul Cariappa <vipul_cariappa>
Destructor gets executed, even if the constructor fails and throws an error,
in a classdef.

My Code (Also attached):

classdef myclass < handle

    properties
        value
    endproperties

    methods

        function self = myclass (x)
            self.value = x;
            % stuff related to acquiring memory
        endfunction

        function delete (self)
            fprintf ('myclass Delete called\n');
            % stuff related to freeing memory
        endfunction
    endmethods

endclassdef


Output:

octave:1> myclass()
error: 'x' undefined near line 10, column 26
error: called from
    myclass at line 10 column 24
myclass Delete called


The "myclass Delete called" should not have been displayed, because the
construction of myclass actually failed. 

To me, this looks like an error. I believe that the destructor should not be
called if the constructor fails.






    _______________________________________________________
File Attachments:


-------------------------------------------------------
Date: Tue 23 May 2023 02:50:31 PM UTC  Name: myclass.m  Size: 395B   By:
vipul_cariappa

<http://savannah.gnu.org/bugs/download.php?file_id=54773>

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?64242>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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