<html><head></head><body bgcolor="#FFFFFF"><div>You need to add the exception to a throws clause or surround the statement with a try-catch.</div><div><br>On 27 Sep 2013, at 15:24, Phil &lt;<a href="mailto:cwstorm@gmail.com">cwstorm@gmail.com</a>&gt; wrote:<br><br></div><div><span></span></div><blockquote type="cite"><div><div dir="ltr">Okay. &nbsp;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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^</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. &nbsp;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>&gt; On Sep 27, 2013, at 9:40 AM, Tim Watson &lt;<a href="mailto:tim@rabbitmq.com" target="_blank">tim@rabbitmq.com</a>&gt; wrote:
<br>&gt; 
<br>&gt; Phil,
<br>&gt; 
<br>&gt;&gt; On 27 Sep 2013, at 14:31, Phil wrote:
<br>&gt;&gt; I'm a newbie on RabbitMQ. &nbsp;I'm writing a java service to consume a message from the queue. &nbsp;Everything is working as designed but I cannot seem to code "channel.close() or conn.close()" in the catch &nbsp;or finally block. &nbsp;Java is complaining about that the "cannot find symbol".
<br>&gt;&gt; 
<br>&gt;&gt; symbol &nbsp;: variable channel
<br>&gt;&gt; location: class RouteToMercury.javaServices
<br>&gt;&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;channel.close();
<br>&gt; 
<br>&gt; It's impossible to help with a compiler error if you don't post that code that you're trying to compile.
<br>&gt; 
<br>&gt;&gt; Can I close the connection and channel if an exception occur?
<br>&gt; 
<br>&gt; Yes, absolutely. The above looks like a scoping issue. I suspect you've done something like...
<br>&gt; 
<br>&gt; try {
<br>&gt; &nbsp;final Channel channel = connection.createChannel();
<br>&gt; &nbsp;doSomeWork(channel);
<br>&gt; } finally {
<br>&gt; &nbsp;channel.close();
<br>&gt; }
<br>&gt; 
<br>&gt; Am I right? If so, you need to move the channel variable to the outer scope.
<br>&gt; 
<br>&gt; Cheers,
<br>&gt; Tim
<br>&gt; ______________________________<wbr>_________________
<br>&gt; rabbitmq-discuss mailing list
<br>&gt; <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.<wbr>rabbitmq.com</a>
<br>&gt; <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></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>rabbitmq-discuss mailing list</span><br><span><a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a></span><br><span><a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a></span><br></div></blockquote></body></html>