View source code
Display the source code in std/csv.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Class std.csv.CSVException

Exception containing the row and column for when an exception was thrown.

class CSVException
  : Exception ;

Numbering of both row and col start at one and corresponds to the location in the file rather than any specified header. Special consideration should be made when there is failure to match the header see HeaderMismatchException for details.

When performing type conversions, ConvException is stored in the next field.

Fields

NameTypeDescription
col ulong
row ulong
file stringThe file name of the D source code corresponding with where the error was thrown from.
info object.Throwable.TraceInfoThe stack trace of where the error happened. This is an opaque object that can either be converted to string, or iterated over with foreach to extract the items in the stack trace (as strings).
line ulongThe line number of the D source code corresponding with where the error was thrown from.
msg stringA message describing the error.

Properties

NameTypeDescription
next[get] inout(Throwable)
next[set] ThrowableReplace next in chain with tail. Use chainTogether instead if at all possible.

Methods

NameDescription
chainTogether () Append e2 to chain of exceptions that starts with e1.
factory (classname) Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor.
message () Get the message describing the error.
opApply (dg) Loop over the chain of Throwables.
opCmp (o) Compare with another Object obj.
opEquals (o) Test whether this is equal to o. The default implementation only compares by identity (using the is operator). Generally, overrides and overloads for opEquals should attempt to compare objects by their contents. A class will most likely want to add an overload that takes your specific type as the argument and does the content comparison. Then you can override this and forward it to your specific typed overload with a cast. Remember to check for null on the typed overload.
refcount ()
toHash () Compute hash function for Object.
toString () Overrides Object.toString and returns the error message. Internally this forwards to the toString overload that takes a sink delegate.
toString () The Throwable hierarchy uses a toString overload that takes a sink delegate to avoid GC allocations, which cannot be performed in certain error situations. Override this toString method to customize the error message.

Example

import std.exception : collectException;
import std.algorithm.searching : count;
string text = "a,b,c\nHello,65";
auto ex = collectException!CSVException(csvReader(text).count);
// "(Row: 0, Col: 0) Row 2's length 2 does not match previous length of 3."
writeln(ex.toString);

Example

import std.exception : collectException;
import std.algorithm.searching : count;
import std.typecons : Tuple;
string text = "a,b\nHello,65";
auto ex = collectException!CSVException(csvReader!(Tuple!(string,int))(text).count);
// "(Row: 1, Col: 2) Unexpected 'b' when converting from type string to type int"
writeln(ex.toString);

Authors

Jesse Phillips

License

Boost License 1.0.