<div dir="ltr">Okay. Here's my code:<div><br></div><div><div>ConnectionFactory factory = new ConnectionFactory();</div><div>factory.setUri("amqp://guest:guest@host:5672");</div><div>Connection conn = factory.newConnection();</div><div>Channel channel = conn.createChannel();</div><div><br></div><div>Got compiling error:</div><div><br></div><div><div>unreported exception java.net.URISyntaxException; must be caught or declared to be thrown</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>factory.setUri("");</div><div> ^</div><div>unreported exception java.io.IOException; must be caught or declared to be thrown</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Connection conn = factory.newConnection();</div><div> ^</div><div>unreported exception java.io.IOException; must be caught or declared to be thrown</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Channel channel = conn.createChannel();</div></div><br>On Friday, September 27, 2013 10:13:24 AM UTC-4, Phil wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">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.
<br>
<br>Sent from mobile device with autocorrect.
<br>
<br>Phil
<br>
<br>> On Sep 27, 2013, at 9:40 AM, Tim Watson <<a href="mailto:tim@rabbitmq.com" target="_blank">tim@rabbitmq.com</a>> wrote:
<br>>
<br>> Phil,
<br>>
<br>>> On 27 Sep 2013, at 14:31, Phil wrote:
<br>>> 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".
<br>>>
<br>>> symbol : variable channel
<br>>> location: class RouteToMercury.javaServices
<br>>> channel.close();
<br>>
<br>> It's impossible to help with a compiler error if you don't post that code that you're trying to compile.
<br>>
<br>>> Can I close the connection and channel if an exception occur?
<br>>
<br>> Yes, absolutely. The above looks like a scoping issue. I suspect you've done something like...
<br>>
<br>> try {
<br>> final Channel channel = connection.createChannel();
<br>> doSomeWork(channel);
<br>> } finally {
<br>> channel.close();
<br>> }
<br>>
<br>> Am I right? If so, you need to move the channel variable to the outer scope.
<br>>
<br>> Cheers,
<br>> Tim
<br>> ______________________________<wbr>_________________
<br>> rabbitmq-discuss mailing list
<br>> <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.<wbr>rabbitmq.com</a>
<br>> <a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/<wbr>cgi-bin/mailman/listinfo/<wbr>rabbitmq-discuss</a>
<br></blockquote></div></div>