1
votes

I have started using cassandraemon (Apache Cassandra NoSQL with C#) and I just wonder if there is any way to read "Why" value in exception being caught from executing CQL query?

When I do the following:

try
{
    CqlResult createResult = context.ExecuteCqlQuery(createTableCql);
}
catch (Exception exc)
{
    if (exc.Why.Contains("already existing"))
    { // Why = org.apache.cassandra.exceptions.AlreadyExistsException: Cannot add already existing column family "nameOfColumn" to keyspace "nameOfKeyspace"
    }
}

I cannot access Why in exc in any way.

What I want to do is to check if table already exists. I know I can check it like here (How to check if a Cassandra table exists), however only in CQL3. The way described in this link does not help too because I get other exception with Why value "unconfigured columnfamily schema_columnfamilies".

I would like to know how to read content of "Why" in general because I may need it in other context in the future. And it does not simply return some kind of CqlResult value that I can check, it just throws an exception.

How to check value of "Why" in caught exception from executing CQL query?

Regards!

PS In order to avoid hidden crossposting: https://cassandraemon.codeplex.com/discussions/441028

1
Can you show the cql code you are using to verify if a table exists? - Lyuben Todorov

1 Answers

1
votes

The error tells you that the table (aka column family) you are looking for doesn't exist, but the schema_columnfamilies table should always exist so the problem is most likely that you are not specifying which schema (aka keyspace) the table is located in.

This statement assumes that you've specified that you are using the system keyspace:

SELECT columnfamily_name 
FROM schema_columnfamilies WHERE keyspace_name='keyspaceName';

I think you are not specifying that you should use the system keyspace, so try this as your CQL statement to verify that a table exists.

SELECT columnfamily_name
FROM system.schema_columnfamilies WHERE keyspace_name='keyspaceName';