I tried catching RuntimeException as well as catching TopicExistsException, but the problem seems to be that the catch block is not being invoked at all.
Is it possible that the scala code needs to have an @throws annotation? sgg On Nov 5, 2013, at 2:24 PM, <sggra...@nc.rr.com> wrote: > Hi All: > I am trying to programmatically create Topics from a Java client. > > I am using a suggestion from > http://stackoverflow.com/questions/16946778/how-can-we-create-a-topic-in-kafka-from-the-ide-using-api/18480684#18480684 > > Essentially invoking the CreateTopicCommand.main(). > > String [] arguments = new String[8]; > arguments[0] = "--zookeeper"; > arguments[1] = "localhost:2181"; > arguments[2] = "--replica"; > arguments[3] = "1"; > arguments[4] = "--partition"; > arguments[5] = "5"; > arguments[6] = "--topic"; > arguments[7] = "someTopicName"; > > try{ > CreateTopicCommand.main(arguments); > }catch(Exception e){ > System.out.println("Topic someTopicName exists."); > } > > This code works fine the first time it is run (i.e. the Topic does not yet > exist). > > Unfortunately, when this is run a second time, an exception is thrown from > Scala that the Java catch block DOES NOT CATCH! > > I tried using the ListTopicsCommand, but there is no boolean response to > verify if the topic already exists. > > Any suggestions? > > thanks > sgg