Probably becasue err is nil, so raise does nothing.

if ID = -1 then
   ShowError "..."
   err= new NilObjectException
   err.Message = "Attach failed"
   raise err
end


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> Dobbs, Paul
> Sent: Wednesday, March 07, 2007 1:42 PM
> To: REALbasic NUG
> Subject: Exception question
>
>
> I have a class constructor which is supposed to signal failure by
> raising an exception. Here is the code for the constructor:
>
> Sub Constructor(Key As Integer, Size As Integer)
>   Soft Declare Function GetShm Lib "libc" Alias "shmget" (theKey As
> Integer, Size As Integer, Flags As Integer) As Integer
>   Soft Declare Function Attach Lib "libc" Alias "shmat" (shmid As
> Integer, Addr As Ptr, Flags As Integer) As Ptr
>
>   Dim ID As Integer
>   Dim P As Ptr
>   Dim err As NilObjectException
>
>   ID = GetShm(Key, Size, Bitwise.BitOr(0600, ipc_creat))
>   If ID = -1 Then
>     ShowError "Get failed with the error: " +
> libcErrorMessage(ErrorCode)
>     Raise err
>   End If
>
>   P = Attach(ID, Nil, 0)
>   If P = Ptr(-1) Then
>     ShowError "Attach failed with the error: " +
> libcErrorMessage(ErrorCode)
>     Raise err
>   End If
>
>   TheMemory = P
> End Sub
>
> Here is the code from which the constructor is being called (in the open
> event of the main window):
>
> Try
>    SharedMem = New SharedMemory(Key, StructSize)
> Catch Err As NilObjectException
>    Dim MD As New MessageDialog
>
>    MD.Icon = MessageDialog.GraphicStop
>    MD.ActionButton.Caption = "Ok"
>    MD.Title = "Fatal Error"
>    MD.Message = "The shared memory block could not be created. The
> program will exit."
>
>    Call MD.ShowModal
>    Quit
> End Try
>
> The routine ShowError simply puts up a messagedialog with the passed
> error message.
>
> When the program is run in an environment which ensures that the call to
> GetSHM will return -1, the error for the call to GetSHM is displayed,
> then an error for the call to Attach is displayed, then the program
> exits.
>
> Questions:
>
> 1. If an exception is being raised after the call to GetSHM, how is the
> program getting to the call to Attach?
> 2. Why is the exception handler in the Catch not being called?
>
> Obviously, there is something that I don't understand about exception
> handling in RB.
>
> Paul Dobbs
> Software Engineer, Staff
> Lockheed Martin Missiles and Fire Control
> Phone (972) 603-1244
> Fax (972) 603-2017
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date:
> 3/7/2007 9:24 AM
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.7/713 - Release Date: 3/7/2007
9:24 AM

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to