internal static unsafe void hNE(NEOERR* err) { if ((IntPtr)err == (IntPtr)0) { return; // no error } // would be nice if we could get nerr_error_string to work... IntPtr buf = (IntPtr)0; byte[] empty_string = new byte[]{ 0 }; string msg = null; string msg_tb = null; STRING neo_string; try { buf = Marshal.AllocHGlobal(8000); Marshal.Copy(empty_string, 0, buf, 1); neo_string.buf = (STR *)buf; neo_string.len = 0; neo_string.max = 8000; // get the error string nerr_error_string(err, &neo_string); msg = Marshal.PtrToStringAnsi(buf); // get the full traceback string Marshal.Copy(empty_string, 0, buf, 1); neo_string.len = 0; nerr_error_traceback(err, &neo_string); msg_tb = Marshal.PtrToStringAnsi(buf); } finally { if (buf != (IntPtr)0) { Marshal.FreeHGlobal(buf); } } // get as much as we can out of the neoerr structure _neo_err info = (_neo_err)Marshal.PtrToStructure((IntPtr)err, typeof(_neo_err)); string csfilename = Marshal.PtrToStringAnsi((IntPtr)info.file); string reason = String.Format("NeoErr: {0}", msg); // free the NEOERR structure nerr_ignore(&err); // throw a real exception throw new NeoException(reason,msg_tb); }
private static unsafe extern void nerr_error_traceback(NEOERR* err, STRING* info);
private static unsafe extern void nerr_ignore(NEOERR** err);
private static unsafe extern void nerr_error_string(NEOERR *err, STRING* info);