1

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user1809566
  • 175
  • 1
  • 4
  • 15

1 Answers1

1

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';
Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • Hello, thank you for your answer. However my question is **how to check value of "Why" in caught exception in runtime**, rather than what this exact exception means because I already knew what you have explained. I know I should avoid this kind of things in my code and I do. However, I prefer to raise meaningful exceptions if something what should not happen, happens. This is just assumption that things that should never happen, may happen and I should be prepared for that. In realistic scenario this exception should never be raised from executing CQL but I want to be prepared. – user1809566 Apr 27 '13 at 16:36