You need to add the exception to a throws clause or surround the statement with 
a try-catch.

On 27 Sep 2013, at 15:24, Phil <[email protected]> wrote:

> Okay.  Here's my code:
> 
> ConnectionFactory factory = new ConnectionFactory();
> factory.setUri("amqp://guest:guest@host:5672");
> Connection conn = factory.newConnection();
> Channel channel = conn.createChannel();
> 
> Got compiling error:
> 
> unreported exception java.net.URISyntaxException; must be caught or declared 
> to be thrown
>               factory.setUri("");
>                               ^
> unreported exception java.io.IOException; must be caught or declared to be 
> thrown
>               Connection conn = factory.newConnection();
>                                                        ^
> unreported exception java.io.IOException; must be caught or declared to be 
> thrown
>               Channel channel = conn.createChannel();
> 
> On Friday, September 27, 2013 10:13:24 AM UTC-4, Phil wrote:
> Thank you everyone and you guys are absolutely correct.  I thought I had to 
> declare the connection and channel inside the try block because exception 
> need to be thrown or caught. 
> 
> Sent from mobile device with autocorrect. 
> 
> Phil 
> 
> > On Sep 27, 2013, at 9:40 AM, Tim Watson <[email protected]> wrote: 
> > 
> > Phil, 
> > 
> >> On 27 Sep 2013, at 14:31, Phil wrote: 
> >> I'm a newbie on RabbitMQ.  I'm writing a java service to consume a message 
> >> from the queue.  Everything is working as designed but I cannot seem to 
> >> code "channel.close() or conn.close()" in the catch  or finally block.  
> >> Java is complaining about that the "cannot find symbol". 
> >> 
> >> symbol  : variable channel 
> >> location: class RouteToMercury.javaServices 
> >>            channel.close(); 
> > 
> > It's impossible to help with a compiler error if you don't post that code 
> > that you're trying to compile. 
> > 
> >> Can I close the connection and channel if an exception occur? 
> > 
> > Yes, absolutely. The above looks like a scoping issue. I suspect you've 
> > done something like... 
> > 
> > try { 
> >  final Channel channel = connection.createChannel(); 
> >  doSomeWork(channel); 
> > } finally { 
> >  channel.close(); 
> > } 
> > 
> > Am I right? If so, you need to move the channel variable to the outer 
> > scope. 
> > 
> > Cheers, 
> > Tim 
> > _______________________________________________ 
> > rabbitmq-discuss mailing list 
> > [email protected] 
> > https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss 
> _______________________________________________
> rabbitmq-discuss mailing list
> [email protected]
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

-- 
You received this message because you are subscribed to the Google Groups 
"rabbitmq-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rabbitmq-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to