aspose file tools*
The moose likes Java in General and the fly likes Is it possible to supress the exception with annotations ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is it possible to supress the exception with annotations ?" Watch "Is it possible to supress the exception with annotations ?" New topic
Author

Is it possible to supress the exception with annotations ?

samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
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

Joined: Oct 25, 2008
Posts: 2700

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:


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 27, 2005
Posts: 192
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 27, 2005
Posts: 192
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 14, 2009
Posts: 28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to supress the exception with annotations ?