You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Mohan Radhakrishnan <ra...@gmail.com> on 2018/01/08 13:02:08 UTC

Catch clause difference

Hello,

These catch clauses are somehow different from each other. Why  ?

In the first case 'NoSuchElementException' is somehow escaping the 'catch'
block. My test fails.

But the second clause succeeds as expected.

Clause 1 :

catch( NoSuchElementException nse ){

    throw new NoSuchWidgetException( " Element " + by.toString() + "
not found" +
                                     " after polling for [" +
pollingInterval.longValue() +
                                     "] with timeout set to [" +
timeOut.longValue() );
}


Clause 2 :

try{
    WaitForWidget<Widget> wait =
    new WaitForWidget<WebDriver>(wd).
                            pollingEvery(pollingInterval.longValue(),unit).
                            withTimeout(timeOut.longValue(),unit).
                            withMessage(supplierClosure)

    wait.until( {  wd.findElement( by )} as Function )
}catch(  nse ){
    throw new NoSuchWidgetException( " Element " + by.toString() + "
not found" +
                                     " after polling for [" +
pollingInterval.longValue() +
                                     "] with timeout set to [" +
timeOut.longValue() );
}

Thanks,
Mohan

Re: Catch clause difference

Posted by Mohan Radhakrishnan <ra...@gmail.com>.
Yes Jochen. That worked.

import org.openqa.selenium.NoSuchElementException

I hadn;t imported anything.

Mohan

On 9 January 2018 at 22:58, Jochen Theodorou <bl...@gmx.org> wrote:

>
>
> Am 09.01.2018 um 16:38 schrieb Dinko Srkoč:
>
>> On 9 January 2018 at 13:26, Mohan Radhakrishnan
>> <ra...@gmail.com> wrote:
>>
>>> I don't see java.util.NoSuchElementException anywhere.
>>>
>>
>>  From the line:
>>
>>      }catch( NoSuchElementException nse ){
>>
>> we don't know which `NoSuchElementException` you're trying to catch
>> (see what is imported), but we do know that the thrown exception is
>> `org.openqa.selenium.NoSuchElementException`.
>>
>> The conclusion is:
>>
>> a) the `NoSuchElementException` in the catch clause shown above is not
>> `org.openqa.selenium.NoSuchElementException`, or
>> b) as Felix noted, different class loaders are being used
>>
>
> if there is no "import org.openqa.selenium.NoSuchElementException" or
> "import org.openqa.selenium.*", then (a) has an extremely high probability
>
> bye Jochen
>

Re: Catch clause difference

Posted by Jochen Theodorou <bl...@gmx.org>.

Am 09.01.2018 um 16:38 schrieb Dinko Srkoč:
> On 9 January 2018 at 13:26, Mohan Radhakrishnan
> <ra...@gmail.com> wrote:
>> I don't see java.util.NoSuchElementException anywhere.
> 
>  From the line:
> 
>      }catch( NoSuchElementException nse ){
> 
> we don't know which `NoSuchElementException` you're trying to catch
> (see what is imported), but we do know that the thrown exception is
> `org.openqa.selenium.NoSuchElementException`.
> 
> The conclusion is:
> 
> a) the `NoSuchElementException` in the catch clause shown above is not
> `org.openqa.selenium.NoSuchElementException`, or
> b) as Felix noted, different class loaders are being used

if there is no "import org.openqa.selenium.NoSuchElementException" or 
"import org.openqa.selenium.*", then (a) has an extremely high probability

bye Jochen

Re: Catch clause difference

Posted by Dinko Srkoč <di...@gmail.com>.
On 9 January 2018 at 13:26, Mohan Radhakrishnan
<ra...@gmail.com> wrote:
> I don't see java.util.NoSuchElementException anywhere.

From the line:

    }catch( NoSuchElementException nse ){

we don't know which `NoSuchElementException` you're trying to catch
(see what is imported), but we do know that the thrown exception is
`org.openqa.selenium.NoSuchElementException`.

The conclusion is:

a) the `NoSuchElementException` in the catch clause shown above is not
`org.openqa.selenium.NoSuchElementException`, or
b) as Felix noted, different class loaders are being used

cheers,
Dinko

>
>
> Mohan
>
> On 9 January 2018 at 15:05, Felix Dorner <fe...@gmail.com> wrote:
>>
>> Or the same exception class but  different classloader? Either of these
>> two.
>>
>> On Jan 9, 2018 10:01, "Dinko Srkoč" <di...@gmail.com> wrote:
>>>
>>> Is your `NoSuchElementException` in the catch clause by any chance
>>> `java.util.NoSuchElementException`?
>>>
>>> cheers,
>>> Dinko
>>>
>>> On 8 January 2018 at 16:18, Mohan Radhakrishnan
>>> <ra...@gmail.com> wrote:
>>> > In the second case it is this.
>>> >
>>> > org.openqa.selenium.NoSuchElementException
>>> >
>>> > In the first case this seems to escape out.
>>> >
>>> > So I changed my first clause to this.
>>> >
>>> > }catch( NoSuchElementException nse ){
>>> >     print "Catch clause " + nse
>>> > }catch( Exception e ){
>>> >     print "Catch clause " + e
>>> > }
>>> >
>>> > It prints org.openqa.selenium.NoSuchElementException if I catch
>>> > 'Exception'.
>>> >
>>> > Does this have anything to do with the 'closure' shown in this trace ?
>>> >
>>> >       at
>>> >
>>> > com.automation.pages.PageObjectLayer$_waitUntil_closure2.doCall(PageObjectLayer.groovy:39)
>>> >       at
>>> > org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
>>> >       at
>>> >
>>> > com.automation.pages.PageObjectLayer.waitUntil(PageObjectLayer.groovy:39)
>>> >       at
>>> >
>>> > com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExceptionWithMessage(WidgetTest.groovy:54)
>>> >
>>> > Thanks.
>>> >
>>> > On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:
>>> >>
>>> >> What does printing out `nse` in both cases show?
>>> >>
>>> >> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan
>>> >> <ra...@gmail.com> wrote:
>>> >>>
>>> >>> Hello,
>>> >>>
>>> >>> These catch clauses are somehow different from each other. Why  ?
>>> >>>
>>> >>> In the first case 'NoSuchElementException' is somehow escaping the
>>> >>> 'catch' block. My test fails.
>>> >>>
>>> >>> But the second clause succeeds as expected.
>>> >>>
>>> >>> Clause 1 :
>>> >>>
>>> >>> catch( NoSuchElementException nse ){
>>> >>>
>>> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
>>> >>> not
>>> >>> found" +
>>> >>>                                      " after polling for [" +
>>> >>> pollingInterval.longValue() +
>>> >>>                                      "] with timeout set to [" +
>>> >>> timeOut.longValue() );
>>> >>> }
>>> >>>
>>> >>>
>>> >>> Clause 2 :
>>> >>>
>>> >>> try{
>>> >>>     WaitForWidget<Widget> wait =
>>> >>>     new WaitForWidget<WebDriver>(wd).
>>> >>>
>>> >>> pollingEvery(pollingInterval.longValue(),unit).
>>> >>>                             withTimeout(timeOut.longValue(),unit).
>>> >>>                             withMessage(supplierClosure)
>>> >>>
>>> >>>     wait.until( {  wd.findElement( by )} as Function )
>>> >>> }catch(  nse ){
>>> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
>>> >>> not
>>> >>> found" +
>>> >>>                                      " after polling for [" +
>>> >>> pollingInterval.longValue() +
>>> >>>                                      "] with timeout set to [" +
>>> >>> timeOut.longValue() );
>>> >>> }
>>> >>>
>>> >>> Thanks,
>>> >>> Mohan
>>> >>
>>> >>
>>> >
>
>

Re: Catch clause difference

Posted by Mohan Radhakrishnan <ra...@gmail.com>.
I don't see java.util.NoSuchElementException anywhere.


Mohan

On 9 January 2018 at 15:05, Felix Dorner <fe...@gmail.com> wrote:

> Or the same exception class but  different classloader? Either of these
> two.
>
> On Jan 9, 2018 10:01, "Dinko Srkoč" <di...@gmail.com> wrote:
>
>> Is your `NoSuchElementException` in the catch clause by any chance
>> `java.util.NoSuchElementException`?
>>
>> cheers,
>> Dinko
>>
>> On 8 January 2018 at 16:18, Mohan Radhakrishnan
>> <ra...@gmail.com> wrote:
>> > In the second case it is this.
>> >
>> > org.openqa.selenium.NoSuchElementException
>> >
>> > In the first case this seems to escape out.
>> >
>> > So I changed my first clause to this.
>> >
>> > }catch( NoSuchElementException nse ){
>> >     print "Catch clause " + nse
>> > }catch( Exception e ){
>> >     print "Catch clause " + e
>> > }
>> >
>> > It prints org.openqa.selenium.NoSuchElementException if I catch
>> 'Exception'.
>> >
>> > Does this have anything to do with the 'closure' shown in this trace ?
>> >
>> >       at
>> > com.automation.pages.PageObjectLayer$_waitUntil_closure2.
>> doCall(PageObjectLayer.groovy:39)
>> >       at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.
>> java:208)
>> >       at
>> > com.automation.pages.PageObjectLayer.waitUntil(PageObjectLay
>> er.groovy:39)
>> >       at
>> > com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExc
>> eptionWithMessage(WidgetTest.groovy:54)
>> >
>> > Thanks.
>> >
>> > On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:
>> >>
>> >> What does printing out `nse` in both cases show?
>> >>
>> >> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan
>> >> <ra...@gmail.com> wrote:
>> >>>
>> >>> Hello,
>> >>>
>> >>> These catch clauses are somehow different from each other. Why  ?
>> >>>
>> >>> In the first case 'NoSuchElementException' is somehow escaping the
>> >>> 'catch' block. My test fails.
>> >>>
>> >>> But the second clause succeeds as expected.
>> >>>
>> >>> Clause 1 :
>> >>>
>> >>> catch( NoSuchElementException nse ){
>> >>>
>> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
>> not
>> >>> found" +
>> >>>                                      " after polling for [" +
>> >>> pollingInterval.longValue() +
>> >>>                                      "] with timeout set to [" +
>> >>> timeOut.longValue() );
>> >>> }
>> >>>
>> >>>
>> >>> Clause 2 :
>> >>>
>> >>> try{
>> >>>     WaitForWidget<Widget> wait =
>> >>>     new WaitForWidget<WebDriver>(wd).
>> >>>
>> >>> pollingEvery(pollingInterval.longValue(),unit).
>> >>>                             withTimeout(timeOut.longValue(),unit).
>> >>>                             withMessage(supplierClosure)
>> >>>
>> >>>     wait.until( {  wd.findElement( by )} as Function )
>> >>> }catch(  nse ){
>> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
>> not
>> >>> found" +
>> >>>                                      " after polling for [" +
>> >>> pollingInterval.longValue() +
>> >>>                                      "] with timeout set to [" +
>> >>> timeOut.longValue() );
>> >>> }
>> >>>
>> >>> Thanks,
>> >>> Mohan
>> >>
>> >>
>> >
>>
>

Re: Catch clause difference

Posted by Felix Dorner <fe...@gmail.com>.
Or the same exception class but  different classloader? Either of these
two.

On Jan 9, 2018 10:01, "Dinko Srkoč" <di...@gmail.com> wrote:

> Is your `NoSuchElementException` in the catch clause by any chance
> `java.util.NoSuchElementException`?
>
> cheers,
> Dinko
>
> On 8 January 2018 at 16:18, Mohan Radhakrishnan
> <ra...@gmail.com> wrote:
> > In the second case it is this.
> >
> > org.openqa.selenium.NoSuchElementException
> >
> > In the first case this seems to escape out.
> >
> > So I changed my first clause to this.
> >
> > }catch( NoSuchElementException nse ){
> >     print "Catch clause " + nse
> > }catch( Exception e ){
> >     print "Catch clause " + e
> > }
> >
> > It prints org.openqa.selenium.NoSuchElementException if I catch
> 'Exception'.
> >
> > Does this have anything to do with the 'closure' shown in this trace ?
> >
> >       at
> > com.automation.pages.PageObjectLayer$_waitUntil_closure2.doCall(
> PageObjectLayer.groovy:39)
> >       at org.openqa.selenium.support.ui.FluentWait.until(
> FluentWait.java:208)
> >       at
> > com.automation.pages.PageObjectLayer.waitUntil(
> PageObjectLayer.groovy:39)
> >       at
> > com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetException
> WithMessage(WidgetTest.groovy:54)
> >
> > Thanks.
> >
> > On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:
> >>
> >> What does printing out `nse` in both cases show?
> >>
> >> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan
> >> <ra...@gmail.com> wrote:
> >>>
> >>> Hello,
> >>>
> >>> These catch clauses are somehow different from each other. Why  ?
> >>>
> >>> In the first case 'NoSuchElementException' is somehow escaping the
> >>> 'catch' block. My test fails.
> >>>
> >>> But the second clause succeeds as expected.
> >>>
> >>> Clause 1 :
> >>>
> >>> catch( NoSuchElementException nse ){
> >>>
> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
> not
> >>> found" +
> >>>                                      " after polling for [" +
> >>> pollingInterval.longValue() +
> >>>                                      "] with timeout set to [" +
> >>> timeOut.longValue() );
> >>> }
> >>>
> >>>
> >>> Clause 2 :
> >>>
> >>> try{
> >>>     WaitForWidget<Widget> wait =
> >>>     new WaitForWidget<WebDriver>(wd).
> >>>
> >>> pollingEvery(pollingInterval.longValue(),unit).
> >>>                             withTimeout(timeOut.longValue(),unit).
> >>>                             withMessage(supplierClosure)
> >>>
> >>>     wait.until( {  wd.findElement( by )} as Function )
> >>> }catch(  nse ){
> >>>     throw new NoSuchWidgetException( " Element " + by.toString() + "
> not
> >>> found" +
> >>>                                      " after polling for [" +
> >>> pollingInterval.longValue() +
> >>>                                      "] with timeout set to [" +
> >>> timeOut.longValue() );
> >>> }
> >>>
> >>> Thanks,
> >>> Mohan
> >>
> >>
> >
>

Re: Catch clause difference

Posted by Dinko Srkoč <di...@gmail.com>.
Is your `NoSuchElementException` in the catch clause by any chance
`java.util.NoSuchElementException`?

cheers,
Dinko

On 8 January 2018 at 16:18, Mohan Radhakrishnan
<ra...@gmail.com> wrote:
> In the second case it is this.
>
> org.openqa.selenium.NoSuchElementException
>
> In the first case this seems to escape out.
>
> So I changed my first clause to this.
>
> }catch( NoSuchElementException nse ){
>     print "Catch clause " + nse
> }catch( Exception e ){
>     print "Catch clause " + e
> }
>
> It prints org.openqa.selenium.NoSuchElementException if I catch 'Exception'.
>
> Does this have anything to do with the 'closure' shown in this trace ?
>
> 	at
> com.automation.pages.PageObjectLayer$_waitUntil_closure2.doCall(PageObjectLayer.groovy:39)
> 	at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
> 	at
> com.automation.pages.PageObjectLayer.waitUntil(PageObjectLayer.groovy:39)
> 	at
> com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExceptionWithMessage(WidgetTest.groovy:54)
>
> Thanks.
>
> On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:
>>
>> What does printing out `nse` in both cases show?
>>
>> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan
>> <ra...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> These catch clauses are somehow different from each other. Why  ?
>>>
>>> In the first case 'NoSuchElementException' is somehow escaping the
>>> 'catch' block. My test fails.
>>>
>>> But the second clause succeeds as expected.
>>>
>>> Clause 1 :
>>>
>>> catch( NoSuchElementException nse ){
>>>
>>>     throw new NoSuchWidgetException( " Element " + by.toString() + " not
>>> found" +
>>>                                      " after polling for [" +
>>> pollingInterval.longValue() +
>>>                                      "] with timeout set to [" +
>>> timeOut.longValue() );
>>> }
>>>
>>>
>>> Clause 2 :
>>>
>>> try{
>>>     WaitForWidget<Widget> wait =
>>>     new WaitForWidget<WebDriver>(wd).
>>>
>>> pollingEvery(pollingInterval.longValue(),unit).
>>>                             withTimeout(timeOut.longValue(),unit).
>>>                             withMessage(supplierClosure)
>>>
>>>     wait.until( {  wd.findElement( by )} as Function )
>>> }catch(  nse ){
>>>     throw new NoSuchWidgetException( " Element " + by.toString() + " not
>>> found" +
>>>                                      " after polling for [" +
>>> pollingInterval.longValue() +
>>>                                      "] with timeout set to [" +
>>> timeOut.longValue() );
>>> }
>>>
>>> Thanks,
>>> Mohan
>>
>>
>

Re: Catch clause difference

Posted by Mohan Radhakrishnan <ra...@gmail.com>.
In the second case it is this.

org.openqa.selenium.NoSuchElementException

In the first case this seems to escape out.

So I changed my first clause to this.

}catch( NoSuchElementException nse ){
    print "Catch clause " + nse
}catch( Exception e ){
    print "Catch clause " + e
}

It prints org.openqa.selenium.NoSuchElementException if I catch 'Exception'.

Does this have anything to do with the 'closure' shown in this trace ?

at
com.automation.pages.PageObjectLayer$_waitUntil_closure2.doCall(PageObjectLayer.groovy:39)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208) at
com.automation.pages.PageObjectLayer.waitUntil(PageObjectLayer.groovy:39)
at
com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExceptionWithMessage(WidgetTest.groovy:54)

Thanks.

On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:

> What does printing out `nse` in both cases show?
>
> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan <
> radhakrishnan.mohan@gmail.com> wrote:
>
>> Hello,
>>
>> These catch clauses are somehow different from each other. Why  ?
>>
>> In the first case 'NoSuchElementException' is somehow escaping the
>> 'catch' block. My test fails.
>>
>> But the second clause succeeds as expected.
>>
>> Clause 1 :
>>
>> catch( NoSuchElementException nse ){
>>
>>     throw new NoSuchWidgetException( " Element " + by.toString() + " not found" +
>>                                      " after polling for [" + pollingInterval.longValue() +
>>                                      "] with timeout set to [" + timeOut.longValue() );
>> }
>>
>>
>> Clause 2 :
>>
>> try{
>>     WaitForWidget<Widget> wait =
>>     new WaitForWidget<WebDriver>(wd).
>>                             pollingEvery(pollingInterval.longValue(),unit).
>>                             withTimeout(timeOut.longValue(),unit).
>>                             withMessage(supplierClosure)
>>
>>     wait.until( {  wd.findElement( by )} as Function )
>> }catch(  nse ){
>>     throw new NoSuchWidgetException( " Element " + by.toString() + " not found" +
>>                                      " after polling for [" + pollingInterval.longValue() +
>>                                      "] with timeout set to [" + timeOut.longValue() );
>> }
>>
>> Thanks,
>> Mohan
>>
>
>

Re: Catch clause difference

Posted by Paul King <pa...@asert.com.au>.
What does printing out `nse` in both cases show?

On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan <
radhakrishnan.mohan@gmail.com> wrote:

> Hello,
>
> These catch clauses are somehow different from each other. Why  ?
>
> In the first case 'NoSuchElementException' is somehow escaping the
> 'catch' block. My test fails.
>
> But the second clause succeeds as expected.
>
> Clause 1 :
>
> catch( NoSuchElementException nse ){
>
>     throw new NoSuchWidgetException( " Element " + by.toString() + " not found" +
>                                      " after polling for [" + pollingInterval.longValue() +
>                                      "] with timeout set to [" + timeOut.longValue() );
> }
>
>
> Clause 2 :
>
> try{
>     WaitForWidget<Widget> wait =
>     new WaitForWidget<WebDriver>(wd).
>                             pollingEvery(pollingInterval.longValue(),unit).
>                             withTimeout(timeOut.longValue(),unit).
>                             withMessage(supplierClosure)
>
>     wait.until( {  wd.findElement( by )} as Function )
> }catch(  nse ){
>     throw new NoSuchWidgetException( " Element " + by.toString() + " not found" +
>                                      " after polling for [" + pollingInterval.longValue() +
>                                      "] with timeout set to [" + timeOut.longValue() );
> }
>
> Thanks,
> Mohan
>