Mercurial > projects > mde
diff mde/mergetag/read.d @ 11:b940f267419e
Options class created & changes to mergetag exception messages.
Options class created (barebones). Loading/saving from Init.
Init no longer runs cleanup functions after initialisation failure.
Improved mergetag exception messages & error reporting.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 21 Feb 2008 09:05:33 +0000 |
parents | 4c3575400769 |
children | bff0d802cb7d |
line wrap: on
line diff
--- a/mde/mergetag/read.d Mon Feb 18 11:54:56 2008 +0000 +++ b/mde/mergetag/read.d Thu Feb 21 09:05:33 2008 +0000 @@ -38,8 +38,16 @@ * // get your data from foo.dataset. * ----------------------- * - * Only a child-class of MTException will ever be thrown, currently MTFileIOException if the file - * could not be read or MTFileFormatException on any error when parsing the file. + * Throws: + * $(TABLE + * $(TR $(TH Exception) $(TH Thrown when)) + * $(TR $(TD MTFileIOException) $(TD An error occurs while opening the file)) + * $(TR $(TD MTFileFormatException) $(TD The file doesn't start with a recognised header/version)) + * $(TR $(TD MTSyntaxException) $(TD A file syntax error occurs)) + * $(TR $(TD MTException) $(TD An unexpected error occurs)) + * ) + * Note that all exceptions extend MTException and when any exception is thrown the class is + * rendered unusable: any subsequent calls to read will be ignored. * * Threading: Separate instances of Reader should be thread-safe provided access to the same * dataset is synchronized; i.e. no two readers refering to the same dataset should run @@ -161,9 +169,6 @@ } else endOfHeader = parseSection (6,null); } - // Was intended to close file, but file is closed within CTOR anyway. - public ~this () { - } //END METHODS: CTOR / DTOR //BEGIN METHODS: PUBLIC @@ -306,7 +311,7 @@ // Type section of tag: uint pos_s = pos; fbufLocateDataTagChar (pos, false); // find end of type section - if (fbuf[pos] != '|') throwMTErr (ErrDTAG); + if (fbuf[pos] != '|') throwMTErr (ErrDTAG, new MTSyntaxException); char[] type = fbuf[pos_s..pos]; fbufIncrement (pos); @@ -314,15 +319,15 @@ // ID section of tag: pos_s = pos; fbufLocateDataTagChar (pos, false); // find end of type section - if (fbuf[pos] != '=') throwMTErr (ErrDTAG); + if (fbuf[pos] != '=') throwMTErr (ErrDTAG, new MTSyntaxException); ID tagID = cast(ID) fbuf[pos_s..pos]; fbufIncrement (pos); // Data section of tag: pos_s = pos; - fbufLocateDataTagChar (pos, true); // find end of data section - if (fbuf[pos] != '>') throwMTErr (ErrDTAG); + fbufLocateDataTagChar (pos, true); // find end of data section + if (fbuf[pos] != '>') throwMTErr (ErrDTAG, new MTSyntaxException); char[] data = fbuf[pos_s..pos]; if (!comment && dsec != null) { @@ -341,7 +346,7 @@ catch (Exception e) { logger.error ("Unknown error occured" ~ ErrInFile ~ ':'); logger.error (e.msg); - throw e; // Fatal to Reader + throwMTErr (e.msg); // Fatal to Reader } } else comment = false; // cancel comment status now } @@ -365,7 +370,7 @@ comment = true; // starting a comment (or an error) // variable is reset at end of comment } else // must be an error - throwMTErr ("Invalid character (or sequence starting \"!\") outside of tag" ~ ErrInFile); + throwMTErr ("Invalid character (or sequence starting \"!\") outside of tag" ~ ErrInFile, new MTSyntaxException); } // if code execution reaches here, we're at EOF // possible error: last character was ! (but don't bother checking since it's inconsequential) @@ -383,7 +388,7 @@ for (; pos < fbuf.length; ++pos) if (fbuf[pos] == '}' || fbuf[pos] == '{') break; - if (fbuf[pos] != '}') throwMTErr ("Bad section tag format: not {id}" ~ ErrInFile); + if (fbuf[pos] != '}') throwMTErr ("Bad section tag format: not {id}" ~ ErrInFile, new MTSyntaxException); ID id = cast(ID) fbuf[start..pos]; fbufIncrement(pos); return id; @@ -392,10 +397,10 @@ /* Increments pos and checks it hasn't hit fbuf.length . */ private void fbufIncrement(inout uint pos) { ++pos; - if (pos >= fbuf.length) throwMTErr("Unexpected EOF" ~ ErrInFile); + if (pos >= fbuf.length) throwMTErr("Unexpected EOF" ~ ErrInFile, new MTSyntaxException); } - private void throwMTErr (char[] msg, MTException exc = new MTFileFormatException) { + private void throwMTErr (char[] msg, MTException exc = new MTException) { fatal = true; // if anyone catches the error and tries to do anything --- we're dead now logger.error (msg); // report the error throw exc; // and signal our error