// -------------------- // // -- object file io -- // // -------------------- // /// <summary> /// Saves an object file to a file. /// </summary> /// <param name="path">the destination file to save to</param> /// <param name="obj">the object file to save</param> private static int SaveObjectFile(string path, ObjectFile obj) { try { obj.Save(path); return(0); } // things from File.OpenRead catch (ArgumentNullException) { Console.Error.WriteLine("Path was null"); return((int)AsmLnkErrorExt.NullPath); } catch (ArgumentException) { Console.Error.WriteLine($"Path \"{path}\" was invalid"); return((int)AsmLnkErrorExt.InvalidPath); } catch (PathTooLongException) { Console.Error.WriteLine($"Path \"{path}\" was too long"); return((int)AsmLnkErrorExt.InvalidPath); } catch (DirectoryNotFoundException) { Console.Error.WriteLine($"Path \"{path}\" directory was not found"); return((int)AsmLnkErrorExt.DirectoryNotFound); } catch (UnauthorizedAccessException) { Console.Error.WriteLine($"You do not have permission to open \"{path}\" for reading"); return((int)AsmLnkErrorExt.AccessViolation); } catch (FileNotFoundException) { Console.Error.WriteLine($"File \"{path}\" could not be found"); return((int)AsmLnkErrorExt.FileNotFound); } catch (NotSupportedException) { Console.Error.WriteLine($"Path \"{path}\" was of an unsupported format"); return((int)AsmLnkErrorExt.PathFormatUnsupported); } catch (IOException) { Console.Error.WriteLine($"An error occurred while reading file \"{path}\""); return((int)AsmLnkErrorExt.IOError); } // everything else that might happen for some reason catch (Exception ex) { Console.Error.WriteLine($"An error occurred while attempting to execute \"{path}\"\n-> {ex}"); return((int)AsmLnkErrorExt.UnknownError); } }