Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Kafka, mail # user - Handling Scala exceptions from ListTopicsCommand in Java


Copy link to this message
-
Re: Handling Scala exceptions from ListTopicsCommand in Java
Edward Capriolo 2013-11-05, 21:16
Actually that will not help. The main probably swallows the exception.
On Tue, Nov 5, 2013 at 4:13 PM, Edward Capriolo <[EMAIL PROTECTED]>wrote:

> Maybe try catching RuntimeException
>
>
> On Tue, Nov 5, 2013 at 2:24 PM, <[EMAIL PROTECTED]> 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
>>
>
>