Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to supress the exception with annotations ?

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers
Can anybody please let me know whether it is possible to supress the exception that might occor in the method execution with the help of annotation. ? What I am looking for is



In the above method @SomeAnnotation should do the magic of supressing all the exceptions that might occour while method execution.
The typical use case is, while running the tests if any of the statement fails to pass , entire execution of the test gets halted. I dont want that to happen.
Any white paper. link will greatly be appriciated
Thanks in advance
Samir
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you can suppress warnings with @SuppressWarnings. I don't think it is possible to do what you want unless you start messing with java-byte-code manipulators (such as javassist).
But why not surround it with:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your test code can throw exceptions then you shouldn't be ignoring them--that should be part of the tests.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Wouter and David
Thanks a lot for the quick reply . I agree with Wouter that we can surround the the statement with try catch . But considering 10000 lines of code, it will be very difficult to manage the code. That is the reason I want to go for something else

David,
I do agree that if the exception is thrown , then it should be handled by the developer. But in case of selenium test suite, even if one test fails (i.e. exception thrown is not caught ) rest of the test cases dont run and execution process halts. I want to get rid of this so that complete test suit will run and a complete report with fail and pass test cases can be produce.
Please let me know your comments on the same
Thanks in advance
Samir

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no such magical annotation. You should check the documentation of your test suite to see if you can run all tests without halting.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes...I do agree. There is no such annotation provided out of the box by JDK . But can we write one ? Can anybody please guide me on the same line ?
Thanks,
Samir
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marking a method with an annotation doesn't do any magic either. You can a method with a custom annotation called @Burp, but it's not going to make it burp by itself. The piece of code using this method will have to check that the method is annotated, and make it burp.

The test suite software would need to interpret such an annotation. So if you made the test suite software, you can make changes so that any method marked with the annotation should be skipped when an exception occurs. So the big question is : Did you make the test suite software, or are you using a third party software ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What test suite are you using? If a single test fails because an exception, that test should fail--that test should not keep running.

The test suites I use (JUnit, TestNG) don't stop running *all* tests because a single one fails.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,
We are trying to run Selenium test at our end. In case of JsUnit test we can specify the flag which will determine whether to halt the execution on test failure or not .Bu tin case of selenium tests, its not provided yet
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're running Selenium tests via JUnit, then that behavior is controlled via JUnit configuration--I'm still not sure what the actual issue is, because we're running Selenium tests and the test suite doesn't just stop if a single test throws an exception.
 
Kaustav Ganguly
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with David. we have also used selenium via junit and failure of one test case do not stop the execution of further tests. But it has happened once when test cases were not executed and we found it was due to out of memory on the selenium server. So make sure the exception you are getting is not something which halts the selenium server itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic