diff --git a/main/DDF/DefaultEscherRecordFactory.cs b/main/DDF/DefaultEscherRecordFactory.cs index 1ecc69e85..fb91c6719 100644 --- a/main/DDF/DefaultEscherRecordFactory.cs +++ b/main/DDF/DefaultEscherRecordFactory.cs @@ -112,7 +112,7 @@ public virtual EscherRecord CreateRecord(byte[] data, int offset) escherRecord = (EscherRecord)recordConstructor.Invoke(new object[] { }); //escherRecord = (EscherRecord)Activator.CreateInstance(recordConstructor); } - catch (Exception) + catch { return new UnknownEscherRecord(); } @@ -143,7 +143,7 @@ private static Dictionary RecordsToMap(Type[] records) { sid = (short)recordType.GetField("RECORD_ID").GetValue(null); } - catch (Exception) + catch { throw new RecordFormatException( "Unable to determine record types"); diff --git a/main/DDF/EscherTextboxRecord.cs b/main/DDF/EscherTextboxRecord.cs index fb5628b68..c5285a972 100644 --- a/main/DDF/EscherTextboxRecord.cs +++ b/main/DDF/EscherTextboxRecord.cs @@ -172,7 +172,7 @@ public override String ToString() theDumpHex += HexDump.Dump(_thedata, 0, 0); } } - catch (Exception) + catch { theDumpHex = "Error!!"; } @@ -194,7 +194,7 @@ public override String ToXml(String tab) theDumpHex += HexDump.Dump(_thedata, 0, 0); } } - catch (Exception) + catch { theDumpHex = "Error!!"; } diff --git a/main/DDF/UnknownEscherRecord.cs b/main/DDF/UnknownEscherRecord.cs index a56e345c1..25012cb77 100644 --- a/main/DDF/UnknownEscherRecord.cs +++ b/main/DDF/UnknownEscherRecord.cs @@ -200,7 +200,7 @@ public override String ToString() theDumpHex += HexDump.Dump(_thedata, 0, 0); } } - catch (Exception) + catch { theDumpHex = "Error!!"; } diff --git a/main/HPSF/MutableSection.cs b/main/HPSF/MutableSection.cs index aed706511..23a74417f 100644 --- a/main/HPSF/MutableSection.cs +++ b/main/HPSF/MutableSection.cs @@ -279,15 +279,8 @@ public override int Size { if (dirty) { - try - { - size = CalcSize(); - dirty = false; - } - catch (Exception) - { - throw; - } + size = CalcSize(); + dirty = false; } return size; } diff --git a/main/HSSF/Extractor/EventBasedExcelExtractor.cs b/main/HSSF/Extractor/EventBasedExcelExtractor.cs index 989471543..c6f762ddb 100644 --- a/main/HSSF/Extractor/EventBasedExcelExtractor.cs +++ b/main/HSSF/Extractor/EventBasedExcelExtractor.cs @@ -123,19 +123,12 @@ public override String Text get { String text = null; - try - { - TextListener tl = TriggerExtraction(); + TextListener tl = TriggerExtraction(); - text = tl.text.ToString(); - if (!text.EndsWith("\n", StringComparison.Ordinal)) - { - text = text + "\n"; - } - } - catch (IOException) + text = tl.text.ToString(); + if (!text.EndsWith("\n", StringComparison.Ordinal)) { - throw; + text = text + "\n"; } return text; diff --git a/main/HSSF/Extractor/OldExcelExtractor.cs b/main/HSSF/Extractor/OldExcelExtractor.cs index 55a861e42..62c02c491 100644 --- a/main/HSSF/Extractor/OldExcelExtractor.cs +++ b/main/HSSF/Extractor/OldExcelExtractor.cs @@ -84,19 +84,19 @@ public OldExcelExtractor(FileInfo f) { Open(biffStream); } - catch (IOException e) + catch (IOException) { // ensure that the stream is properly closed here if an Exception // is thrown while opening biffStream.Close(); - throw e; + throw; } - catch (RuntimeException e) + catch (RuntimeException) { // ensure that the stream is properly closed here if an Exception // is thrown while opening biffStream.Close(); - throw e; + throw; } } public OldExcelExtractor(NPOIFSFileSystem fs) diff --git a/main/HSSF/Record/RecordFactory.cs b/main/HSSF/Record/RecordFactory.cs index 3c38b0a36..cda2eb9b2 100644 --- a/main/HSSF/Record/RecordFactory.cs +++ b/main/HSSF/Record/RecordFactory.cs @@ -656,7 +656,7 @@ private static I_RecordCreator GetRecordCreator(Type recClass) if (constructor != null) return new ReflectionConstructorRecordCreator(constructor); } - catch (Exception) + catch { // fall through and look for other construction methods } @@ -665,7 +665,7 @@ private static I_RecordCreator GetRecordCreator(Type recClass) MethodInfo m = recClass.GetMethod("Create", CONSTRUCTOR_ARGS); return new ReflectionMethodRecordCreator(m); } - catch (Exception) + catch { throw new RuntimeException("Failed to find constructor or create method for (" + recClass.Name + ")."); } diff --git a/main/HSSF/UserModel/OperationEvaluatorFactory.cs b/main/HSSF/UserModel/OperationEvaluatorFactory.cs index f5e925775..4f6aef695 100644 --- a/main/HSSF/UserModel/OperationEvaluatorFactory.cs +++ b/main/HSSF/UserModel/OperationEvaluatorFactory.cs @@ -86,14 +86,7 @@ private static void Add(Hashtable m, Type ptgClass, Type evalClass) } ConstructorInfo constructor; - try - { - constructor = evalClass.GetConstructor(OPERATION_CONSTRUCTOR_CLASS_ARRAY); - } - catch (Exception) - { - throw; - } + constructor = evalClass.GetConstructor(OPERATION_CONSTRUCTOR_CLASS_ARRAY); if (!constructor.IsPublic) { throw new Exception("Eval constructor must be public"); @@ -128,14 +121,7 @@ public static OperationEval Create(OperationPtg ptg) Object result; Object[] initargs = { ptg }; - try - { - result = constructor.Invoke(initargs); - } - catch (Exception) - { - throw; - } + result = constructor.Invoke(initargs); return (OperationEval)result; } } diff --git a/main/HSSF/Util/HSSFCellUtil.cs b/main/HSSF/Util/HSSFCellUtil.cs index a3005be34..4793bebf2 100644 --- a/main/HSSF/Util/HSSFCellUtil.cs +++ b/main/HSSF/Util/HSSFCellUtil.cs @@ -277,7 +277,7 @@ public static void CopyCell(HSSFCell oldCell, HSSFCell newCell, IDictionarythe source Stream public HeaderBlock(Stream stream) { - try + stream.Position = 0; + PrivateHeaderBlock(ReadFirst512(stream)); + if (bigBlockSize.GetBigBlockSize() != 512) { - stream.Position = 0; - PrivateHeaderBlock(ReadFirst512(stream)); - if (bigBlockSize.GetBigBlockSize() != 512) - { - int rest = bigBlockSize.GetBigBlockSize() - 512; - byte[] temp = new byte[rest]; - IOUtils.ReadFully(stream, temp); - } - - } - catch(IOException ex) - { - throw ex; + int rest = bigBlockSize.GetBigBlockSize() - 512; + byte[] temp = new byte[rest]; + IOUtils.ReadFully(stream, temp); } } @@ -130,15 +122,9 @@ public HeaderBlock(ByteBuffer buffer) public HeaderBlock(byte[] buffer) { - try - { - PrivateHeaderBlock(buffer); - } - catch (IOException ex) - { - throw ex; - } + PrivateHeaderBlock(buffer); } + public void PrivateHeaderBlock(byte[] data) { _data = data; @@ -425,26 +411,19 @@ public POIFSBigBlockSize BigBlockSize public void WriteData(Stream stream) { - try - { - new IntegerField(_bat_count_offset, _bat_count, _data); - new IntegerField(_property_start_offset, _property_start, _data); - new IntegerField(_sbat_start_offset, _sbat_start, _data); - new IntegerField(_sbat_block_count_offset, _sbat_count, _data); - new IntegerField(_xbat_start_offset, _xbat_start, _data); - new IntegerField(_xbat_count_offset, _xbat_count, _data); + new IntegerField(_bat_count_offset, _bat_count, _data); + new IntegerField(_property_start_offset, _property_start, _data); + new IntegerField(_sbat_start_offset, _sbat_start, _data); + new IntegerField(_sbat_block_count_offset, _sbat_count, _data); + new IntegerField(_xbat_start_offset, _xbat_start, _data); + new IntegerField(_xbat_count_offset, _xbat_count, _data); - stream.Write(_data, 0, 512); + stream.Write(_data, 0, 512); - for (int i = POIFSConstants.SMALLER_BIG_BLOCK_SIZE; i < bigBlockSize.GetBigBlockSize(); i++) - { - //stream.Write(Write(0); - stream.WriteByte(0); - } - } - catch (IOException ex) + for (int i = POIFSConstants.SMALLER_BIG_BLOCK_SIZE; i < bigBlockSize.GetBigBlockSize(); i++) { - throw ex; + //stream.Write(Write(0); + stream.WriteByte(0); } } diff --git a/main/POIFS/Storage/HeaderBlockWriter.cs b/main/POIFS/Storage/HeaderBlockWriter.cs index b6146fb77..ccf741af1 100644 --- a/main/POIFS/Storage/HeaderBlockWriter.cs +++ b/main/POIFS/Storage/HeaderBlockWriter.cs @@ -160,14 +160,7 @@ public static int CalculateXBATStorageRequirements(POIFSBigBlockSize bigBlockSiz /// public void WriteBlocks(Stream stream) { - try - { - _header_block.WriteData(stream); - } - catch (IOException ex) - { - throw ex; - } + _header_block.WriteData(stream); } public void WriteBlock(ByteBuffer block) diff --git a/main/POIFS/property/NPropertyTable.cs b/main/POIFS/property/NPropertyTable.cs index ba7be2dea..f316ca7c7 100644 --- a/main/POIFS/property/NPropertyTable.cs +++ b/main/POIFS/property/NPropertyTable.cs @@ -117,27 +117,21 @@ public void PreWrite() public void Write(NPOIFSStream stream) { Stream os = stream.GetOutputStream(); - try + + //Leon ByteArrayOutputStream -->MemoryStream + MemoryStream ms = new MemoryStream(); + foreach (Property property in _properties) { - //Leon ByteArrayOutputStream -->MemoryStream - MemoryStream ms = new MemoryStream(); - foreach (Property property in _properties) - { - if (property != null) - property.WriteData(os); - } + if (property != null) + property.WriteData(os); + } - os.Close(); + os.Close(); - // Update the start position if needed - if (StartBlock != stream.GetStartBlock()) - { - StartBlock = stream.GetStartBlock(); - } - } - catch (System.IO.IOException ex) + // Update the start position if needed + if (StartBlock != stream.GetStartBlock()) { - throw ex; + StartBlock = stream.GetStartBlock(); } } } diff --git a/main/POIFS/property/PropertyTableBase.cs b/main/POIFS/property/PropertyTableBase.cs index a8a85196e..0bb105aa2 100644 --- a/main/POIFS/property/PropertyTableBase.cs +++ b/main/POIFS/property/PropertyTableBase.cs @@ -60,49 +60,41 @@ public RootProperty Root protected void PopulatePropertyTree(DirectoryProperty root) { - try - { - int index = root.ChildIndex; + int index = root.ChildIndex; - if (!Property.IsValidIndex(index)) - return; + if (!Property.IsValidIndex(index)) + return; - Stack children = new Stack(); + Stack children = new Stack(); - children.Push(_properties[index]); + children.Push(_properties[index]); - while (children.Count != 0) + while (children.Count != 0) + { + Property property = children.Pop(); + if (property == null) { - Property property = children.Pop(); - if (property == null) - { - // unknown / unsupported / corrupted property, skip - continue; - } - root.AddChild(property); - - if (property.IsDirectory) - { - PopulatePropertyTree((DirectoryProperty)property); - } - - index = property.PreviousChildIndex; - if (Property.IsValidIndex(index)) - { - children.Push(_properties[index]); - } - - index = property.NextChildIndex; - if (Property.IsValidIndex(index)) - { - children.Push(_properties[index]); - } + // unknown / unsupported / corrupted property, skip + continue; } + root.AddChild(property); - } - catch (IOException ex) - { - throw ex; + if (property.IsDirectory) + { + PopulatePropertyTree((DirectoryProperty)property); + } + + index = property.PreviousChildIndex; + if (Property.IsValidIndex(index)) + { + children.Push(_properties[index]); + } + + index = property.NextChildIndex; + if (Property.IsValidIndex(index)) + { + children.Push(_properties[index]); + } } } diff --git a/main/SS/Format/CellFormat.cs b/main/SS/Format/CellFormat.cs index 5e83458ca..f0479a9d2 100644 --- a/main/SS/Format/CellFormat.cs +++ b/main/SS/Format/CellFormat.cs @@ -168,7 +168,7 @@ private CellFormat(String format) parts.Add(new CellFormatPart(valueDesc)); } - catch (Exception) + catch { //CellFormatter.logger.Log(Level.WARNING, // "Invalid format: " + CellFormatter.Quote(m.Group()), e); diff --git a/main/SS/Format/CellNumberStringMod.cs b/main/SS/Format/CellNumberStringMod.cs index f24aa5607..7e62fdecb 100644 --- a/main/SS/Format/CellNumberStringMod.cs +++ b/main/SS/Format/CellNumberStringMod.cs @@ -81,7 +81,7 @@ public override bool Equals(Object that) { return CompareTo((CellNumberStringMod)that) == 0; } - catch (Exception) + catch { // NullPointerException or CastException return false; diff --git a/main/SS/Formula/Atp/Switch.cs b/main/SS/Formula/Atp/Switch.cs index 747a7a0ca..5073c987e 100644 --- a/main/SS/Formula/Atp/Switch.cs +++ b/main/SS/Formula/Atp/Switch.cs @@ -23,7 +23,7 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) { expression = OperandResolver.GetSingleValue(args[0], ec.RowIndex, ec.ColumnIndex); } - catch (Exception) + catch { return ErrorEval.NA; } diff --git a/main/SS/Formula/Atp/XLookupFunction.cs b/main/SS/Formula/Atp/XLookupFunction.cs index 182e5cd9c..9ad42af4a 100644 --- a/main/SS/Formula/Atp/XLookupFunction.cs +++ b/main/SS/Formula/Atp/XLookupFunction.cs @@ -91,7 +91,7 @@ private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnInde { return e.GetErrorEval(); } - catch (Exception) + catch { return ErrorEval.VALUE_INVALID; } diff --git a/main/SS/Formula/Atp/XMatchFunction.cs b/main/SS/Formula/Atp/XMatchFunction.cs index 431542b36..1fe13d9dd 100644 --- a/main/SS/Formula/Atp/XMatchFunction.cs +++ b/main/SS/Formula/Atp/XMatchFunction.cs @@ -44,7 +44,7 @@ private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnInde { return e.GetErrorEval(); } - catch (Exception e) + catch { return ErrorEval.VALUE_INVALID; } @@ -62,7 +62,7 @@ private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnInde { return e.GetErrorEval(); } - catch (Exception e) + catch { return ErrorEval.VALUE_INVALID; } diff --git a/main/SS/Formula/Eval/OperandResolver.cs b/main/SS/Formula/Eval/OperandResolver.cs index b9f6b2697..992f2dbe1 100644 --- a/main/SS/Formula/Eval/OperandResolver.cs +++ b/main/SS/Formula/Eval/OperandResolver.cs @@ -279,7 +279,7 @@ public static double ParseDouble(String pText) return double.NaN; return ret; } - catch (Exception) + catch { return Double.NaN; } diff --git a/main/SS/Formula/EvaluationConditionalFormatRule.cs b/main/SS/Formula/EvaluationConditionalFormatRule.cs index cdc1b74b8..2da873de2 100644 --- a/main/SS/Formula/EvaluationConditionalFormatRule.cs +++ b/main/SS/Formula/EvaluationConditionalFormatRule.cs @@ -712,7 +712,7 @@ private bool CheckFilter(ICell cell, CellReference reference, CellRangeAddress r // see TextFunction.TRIM for implementation return v == null || v.Trim().Length == 0; } - catch (Exception e) + catch { // not a valid string value, and not a blank cell (that's checked earlier) return false; @@ -724,7 +724,7 @@ private bool CheckFilter(ICell cell, CellReference reference, CellRangeAddress r // see TextFunction.TRIM for implementation return v != null && v.Trim().Length > 0; } - catch (Exception e) + catch { // not a valid string value, but not blank return true; diff --git a/main/SS/Formula/FormulaParser.cs b/main/SS/Formula/FormulaParser.cs index f9361bf04..238354994 100644 --- a/main/SS/Formula/FormulaParser.cs +++ b/main/SS/Formula/FormulaParser.cs @@ -1243,7 +1243,7 @@ private SimpleRangePart ParseSimpleRangePart() { i = Int32.Parse(rep.Replace("$", ""), CultureInfo.InvariantCulture); } - catch (Exception) + catch { return null; } @@ -2435,7 +2435,7 @@ private ParseNode IntersectionExpression() hasIntersections = true; continue; } - catch (FormulaParseException e) + catch (FormulaParseException) { // if parsing for intersection fails we assume that we actually had an arbitrary // whitespace and thus should simply skip this whitespace diff --git a/main/SS/Formula/Function/FunctionMetadataReader.cs b/main/SS/Formula/Function/FunctionMetadataReader.cs index 15d64ea25..d7f8d5c36 100644 --- a/main/SS/Formula/Function/FunctionMetadataReader.cs +++ b/main/SS/Formula/Function/FunctionMetadataReader.cs @@ -60,30 +60,23 @@ public static FunctionMetadataRegistry CreateRegistry() FunctionDataBuilder fdb = new FunctionDataBuilder(400); - try + while (true) { - while (true) + String line = br.ReadLine(); + if (line == null) { - String line = br.ReadLine(); - if (line == null) - { - break; - } - if (line.Length < 1 || line[0] == '#') - { - continue; - } - String TrimLine = line.Trim(); - if (TrimLine.Length < 1) - { - continue; - } - ProcessLine(fdb, line); + break; } - } - catch (IOException) - { - throw; + if (line.Length < 1 || line[0] == '#') + { + continue; + } + String TrimLine = line.Trim(); + if (TrimLine.Length < 1) + { + continue; + } + ProcessLine(fdb, line); } return fdb.Build(); diff --git a/main/SS/Formula/Functions/Areas.cs b/main/SS/Formula/Functions/Areas.cs index b986452d6..757ea9a21 100644 --- a/main/SS/Formula/Functions/Areas.cs +++ b/main/SS/Formula/Functions/Areas.cs @@ -25,7 +25,7 @@ public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) NumberEval numberEval = new NumberEval(new NumberPtg(result)); return numberEval; } - catch (Exception e) + catch { return ErrorEval.VALUE_INVALID; } diff --git a/main/SS/Formula/Functions/NumberValueFunction.cs b/main/SS/Formula/Functions/NumberValueFunction.cs index 736717919..a07cb087d 100644 --- a/main/SS/Formula/Functions/NumberValueFunction.cs +++ b/main/SS/Formula/Functions/NumberValueFunction.cs @@ -89,7 +89,7 @@ public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) { return e.GetErrorEval(); } - catch (Exception) + catch { return ErrorEval.VALUE_INVALID; //If any of the arguments are not valid, NUMBERVALUE returns the #VALUE! error value. } diff --git a/main/SS/Formula/Functions/Sumproduct.cs b/main/SS/Formula/Functions/Sumproduct.cs index 47bee2749..f5f8e9caa 100644 --- a/main/SS/Formula/Functions/Sumproduct.cs +++ b/main/SS/Formula/Functions/Sumproduct.cs @@ -149,7 +149,7 @@ private ValueEval EvaluateAreaSumProduct(ValueEval[] evalArgs) { Array.Copy(evalArgs, 0, args, 0, maxN); } - catch (Exception) + catch { // one of the other args was not an AreaRef return ErrorEval.VALUE_INVALID; diff --git a/main/SS/Formula/Functions/Text/Text.cs b/main/SS/Formula/Functions/Text/Text.cs index 53ec47589..8df3c734c 100644 --- a/main/SS/Formula/Functions/Text/Text.cs +++ b/main/SS/Formula/Functions/Text/Text.cs @@ -34,7 +34,7 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva String formattedStr = Formatter.FormatRawCellContents(s0, -1, s1); return new StringEval(formattedStr); } - catch (Exception) + catch { return ErrorEval.VALUE_INVALID; } diff --git a/main/SS/Formula/WorkbookEvaluator.cs b/main/SS/Formula/WorkbookEvaluator.cs index c0ce65fa9..1cc940c6a 100644 --- a/main/SS/Formula/WorkbookEvaluator.cs +++ b/main/SS/Formula/WorkbookEvaluator.cs @@ -435,7 +435,7 @@ private ValueEval EvaluateAny(IEvaluationCell srcCell, int sheetIndex, } else { - throw re; + throw; } } finally @@ -478,7 +478,7 @@ private NotImplementedException AddExceptionInfo(NotImplementedException inner, String msg = "Error evaluating cell " + cr.FormatAsString(); return new NotImplementedException(msg, inner); } - catch (Exception) + catch { // avoid bombing out during exception handling //e.printStackTrace(); diff --git a/main/SS/Util/SheetUtil.cs b/main/SS/Util/SheetUtil.cs index 14ea82dc2..43123ba52 100644 --- a/main/SS/Util/SheetUtil.cs +++ b/main/SS/Util/SheetUtil.cs @@ -391,7 +391,7 @@ private static string GetCellStringValue(ICell cell) DataFormatter formatter = new DataFormatter(); stringValue = formatter.FormatCellValue(cell, dummyEvaluator); } - catch (Exception) + catch { stringValue = cell.NumericCellValue.ToString(); } @@ -501,7 +501,7 @@ public static double GetCellWidth(ICell cell, int defaultCharWidth, DataFormatte { sval = formatter.FormatCellValue(cell, dummyEvaluator); } - catch (Exception) + catch { sval = cell.NumericCellValue.ToString(); } diff --git a/main/Util/CRC32.cs b/main/Util/CRC32.cs index 07ed31f0c..07c70c8bc 100644 --- a/main/Util/CRC32.cs +++ b/main/Util/CRC32.cs @@ -120,18 +120,11 @@ public long FileCRC(string sInputFilename) /// public long StreamCRC(Stream inFile) { - try - { - byte[] bInput = new byte[inFile.Length]; - inFile.Read(bInput, 0, bInput.Length); - inFile.Close(); + byte[] bInput = new byte[inFile.Length]; + inFile.Read(bInput, 0, bInput.Length); + inFile.Close(); - return (long)ByteCRC(ref bInput); - } - catch (IOException) - { - throw; - } + return (long)ByteCRC(ref bInput); } public ulong Value { get; set; } diff --git a/main/Util/CodePageUtil.cs b/main/Util/CodePageUtil.cs index c57306373..1863ca40a 100644 --- a/main/Util/CodePageUtil.cs +++ b/main/Util/CodePageUtil.cs @@ -219,7 +219,7 @@ public static byte[] GetBytesInCodePage(String string1, int codepage) { encoding = Encoding.GetEncoding(cp); } - catch (Exception) + catch { encoding = Encoding.ASCII; } diff --git a/main/Util/SystemOutLogger.cs b/main/Util/SystemOutLogger.cs index 7ca75ada3..40e415786 100644 --- a/main/Util/SystemOutLogger.cs +++ b/main/Util/SystemOutLogger.cs @@ -82,7 +82,7 @@ public override bool Check(int level) temp = WARN.ToString(CultureInfo.InvariantCulture); currentLevel = int.Parse(temp, CultureInfo.InvariantCulture); } - catch (Exception) + catch { currentLevel = POILogger.DEBUG; } diff --git a/ooxml/POIFS/Crypt/Agile/AgileEncryptionHeader.cs b/ooxml/POIFS/Crypt/Agile/AgileEncryptionHeader.cs index 1c40de0a5..6cf08c361 100644 --- a/ooxml/POIFS/Crypt/Agile/AgileEncryptionHeader.cs +++ b/ooxml/POIFS/Crypt/Agile/AgileEncryptionHeader.cs @@ -42,7 +42,7 @@ protected internal AgileEncryptionHeader(EncryptionDocument ed) throw new NullReferenceException("keyData not Set"); } } - catch (Exception) + catch { throw new EncryptedDocumentException("Unable to parse keyData"); } diff --git a/ooxml/POIXMLDocumentPart.cs b/ooxml/POIXMLDocumentPart.cs index d9b099959..a69cbafea 100644 --- a/ooxml/POIXMLDocumentPart.cs +++ b/ooxml/POIXMLDocumentPart.cs @@ -629,7 +629,7 @@ protected RelationPart CreateRelationship(POIXMLRelation descriptor, POIXMLFacto { // Return the specific exception so the user knows // that the name is already taken - throw pae; + throw; } catch (Exception e) { diff --git a/ooxml/SS/UserModel/WorkbookFactory.cs b/ooxml/SS/UserModel/WorkbookFactory.cs index 9d3a2fb02..d6e97ebf6 100644 --- a/ooxml/SS/UserModel/WorkbookFactory.cs +++ b/ooxml/SS/UserModel/WorkbookFactory.cs @@ -234,23 +234,14 @@ public static IWorkbook Create(Stream inputStream, string password, bool readOnl { return new XSSFWorkbook(pkg); } - catch (IOException ioe) - { - // ensure that file handles are closed (use revert() to not re-write the file) - pkg.Revert(); - //pkg.close(); - - // rethrow exception - throw ioe; - } - catch (Exception ioe) + catch { // ensure that file handles are closed (use revert() to not re-write the file) pkg.Revert(); //pkg.close(); // rethrow exception - throw ioe; + throw; } } } diff --git a/ooxml/XSSF/Streaming/SheetDataWriter.cs b/ooxml/XSSF/Streaming/SheetDataWriter.cs index bb42a6e24..6c08e6f37 100644 --- a/ooxml/XSSF/Streaming/SheetDataWriter.cs +++ b/ooxml/XSSF/Streaming/SheetDataWriter.cs @@ -84,7 +84,7 @@ public virtual Stream CreateWriter(FileInfo fd) { outputStream = DecorateOutputStream(fos); } - catch (Exception) + catch { fos.Close(); throw; @@ -119,7 +119,7 @@ public void Close() _outputWriter.Flush(); OutputStream.Flush(); } - catch (Exception) + catch { } @@ -127,7 +127,7 @@ public void Close() { OutputStream.Close(); } - catch (Exception) + catch { } diff --git a/ooxml/XSSF/UserModel/XSSFSheet.cs b/ooxml/XSSF/UserModel/XSSFSheet.cs index 1a0b0ca4f..e5532b815 100644 --- a/ooxml/XSSF/UserModel/XSSFSheet.cs +++ b/ooxml/XSSF/UserModel/XSSFSheet.cs @@ -5160,7 +5160,7 @@ private static void CopyCell(ICell oldCell, ICell newCell, IDictionary(DateTime.Now)); - } - catch (InvalidFormatException) - { - // Should never happen - throw; - } + // Content type manager + pkg.contentTypeManager = new ZipContentTypeManager(null, pkg); + // Add default content types for .xml and .rels + pkg.contentTypeManager.AddContentType( + PackagingUriHelper.CreatePartName(PackagingUriHelper.PACKAGE_RELATIONSHIPS_ROOT_URI), + ContentTypes.RELATIONSHIPS_PART); + pkg.contentTypeManager.AddContentType(PackagingUriHelper + .CreatePartName("/default.xml"), + ContentTypes.PLAIN_OLD_XML); + + // Init some PackageBase properties + pkg.packageProperties = new PackagePropertiesPart(pkg, + PackagingUriHelper.CORE_PROPERTIES_PART_NAME); + pkg.packageProperties.SetCreatorProperty("Generated by OpenXml4Net"); + pkg.packageProperties.SetCreatedProperty(new Nullable(DateTime.Now)); } /** diff --git a/openxml4Net/OPC/PackagingUriHelper.cs b/openxml4Net/OPC/PackagingUriHelper.cs index fe51839d4..09ceb55ee 100644 --- a/openxml4Net/OPC/PackagingUriHelper.cs +++ b/openxml4Net/OPC/PackagingUriHelper.cs @@ -315,7 +315,7 @@ public static Uri RelativizeUri(Uri sourceURI, Uri targetURI, bool msCompatible) { targetURI = ParseUri(path.Substring(1), UriKind.RelativeOrAbsolute); } - catch (Exception) + catch { //_logger.log(POILogger.WARN, e); return null; @@ -362,7 +362,7 @@ public static Uri RelativizeUri(Uri sourceURI, Uri targetURI, bool msCompatible) { return ParseUri(retVal.ToString(),UriKind.RelativeOrAbsolute); } - catch (Exception) + catch { //System.err.println(e); return null; @@ -421,7 +421,7 @@ public static Uri RelativizeUri(Uri sourceURI, Uri targetURI, bool msCompatible) { return ParseUri(retVal.ToString(), UriKind.RelativeOrAbsolute); } - catch (Exception) + catch { //System.err.println(e); return null; @@ -678,7 +678,7 @@ public static bool IsValidPartName(Uri partUri) CreatePartName(partUri); return true; } - catch (Exception) + catch { return false; } diff --git a/openxml4Net/OPC/ZipPackage.cs b/openxml4Net/OPC/ZipPackage.cs index aaf0f02b7..94198a856 100644 --- a/openxml4Net/OPC/ZipPackage.cs +++ b/openxml4Net/OPC/ZipPackage.cs @@ -332,7 +332,7 @@ private PackagePartName BuildPartName(ZipEntry entry) return PackagingUriHelper.CreatePartName(ZipHelper .GetOPCNameFromZipItemName(entry.Name)); } - catch (Exception) + catch { // We assume we can continue, even in degraded mode ... //logger.log(POILogger.WARN,"Entry " @@ -611,16 +611,10 @@ protected override void SaveImpl(Stream outputStream) else zos.Close(); } - catch (OpenXML4NetRuntimeException e) + catch (OpenXML4NetRuntimeException) { // no need to wrap this type of Exception - throw e; - } - catch (IOException e) - { - throw new OpenXML4NetRuntimeException( - "Fail to save: an error occurs while saving the package : " - + e.Message, e); + throw; } catch (Exception e) {