Beispiel #1
0
        /// <summary>
        /// Loads an object file from a file.
        /// </summary>
        /// <param name="path">the source fie to read from</param>
        /// <param name="obj">the resulting object file (on success)</param>
        private static int LoadObjectFile(string path, ObjectFile obj)
        {
            try
            {
                obj.Load(path);
                return(0);
            }

            // things from CSX64
            catch (TypeError) { Console.Error.WriteLine($"{path} is not a CSX64 object file"); return((int)AsmLnkErrorExt.FormatError); }
            catch (VersionError) { Console.Error.WriteLine($"Object file {path} is of an incompatible version of CSX64"); return((int)AsmLnkErrorExt.FormatError); }
            catch (FormatException) { Console.Error.WriteLine($"Object file {path} is of an unrecognized format"); return((int)AsmLnkErrorExt.FormatError); }

            // things from File.OpenRead
            catch (ArgumentNullException) { Console.Error.WriteLine("Path was null"); return((int)AsmLnkErrorExt.NullPath); }
            catch (ArgumentException ex) { Console.Error.WriteLine($"Path \"{path}\" was invalid\n{ex}"); 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); }

            // things from casting after deserialization
            catch (InvalidCastException) { Console.Error.WriteLine($"file \"{path}\" was incorrectly-formatted"); return((int)AsmLnkErrorExt.FormatError); }

            // 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); }
        }