Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scala exception signature definition using generics
- public interface BaseInterface<T, E extends Throwable> {
- public T process(Class<E> wrapperExc) throws E;
- }
- public class ExcOne extends Exception {}
- public class SubclassOne implements BaseInterface<String, ExcOne> {
- @Override
- public String process(Class<ExcOne> wrapperExc) throws ExcOne {
- return null;
- }
- }
- class UsingGenerics[IN, OUT, E <: Throwable] {
- //@throws(classOf[E]) - error: class type required but E found
- def process(request: IN, wrapperExc: Class[E]): OUT = {
- null.asInstanceOf[OUT]
- }
- }
- trait BaseTrait {
- type Request
- type Response
- type BusinessException <: Throwable
- //error: class type required but BaseTrait.this.BusinessException found
- //@throws(classOf[BusinessException])
- def process(request: Request): Response
- }
- class TraitImplementor extends BaseTrait {
- type Request = Input
- type Response = Output
- type BusinessException = BizExc
- def process(r: Request): Response = {
- if (1 != 2) throw new BusinessException("Bang")
- new Response
- }
- }
- class Input
- class Output
- class BizExc(msg: String) extends Exception(msg)
- public @interface Throwing { Class<? extends Throwable> exceptionType(); }
Add Comment
Please, Sign In to add comment