Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:08:59+00:00 2026-06-16T02:08:59+00:00

How to convert exception catching code from java to scala using intercept ? From

  • 0

How to convert exception catching code from java to scala using intercept ?

From reading http://www.scalatest.org/getting_started_with_fun_suite it seems to be recommended to use intercept when catching exceptions. In the exception catching code below I need to access the Exception type so as to check its type within the
assert :

catch {
          case me : MyException => {
            assert(me.getDetail.getClass() === classOf[GenericException]);
          }
        }

This does not seem to be possible using intercept as below code causes a compiler error : ‘forward reference extends over definition of value exception’

Here is the converted to scala catch block :

        val exception = intercept[MyException] {
assert(exception.getDetail.getClass() === classOf[GenericException]);   
    }

The error occurs on line

assert(exception.getDetail.getClass() === classOf[GenericException]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:09:01+00:00Added an answer on June 16, 2026 at 2:09 am

    Well your definition of exception is circular. What you want is:

    val exception = intercept[MyException] {
       <your exception-throwing code here>
    }
    
    assert(exception.getDetail.getClass() === classOf[GenericException])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using util.control.Exception.catching to convert internal exceptions into an exception type specific to my
I've got exception about convert NULL to Int32. I've got a table from database
How to convert an integer number into its binary representation? I'm using this code:
In my code, if an exception arises, then I want to convert that exception
I'm receiving an exception like cannot convert from 'List' to 'string' when i'm declaring
I receive the exception Failed to convert property value of type [java.lang.String] to required
This line of code: Console.WriteLine(Convert.ToInt32(23,23) + 1); Throws an exception. This line of code:
Why does the statement (int)84 throw an exception and Convert.ToInt32(84) does not throw an
Am just trying to understand why this exception throws. Cannot implicitly convert type 'System.DateTime?'
I convert all links from example.com/action to example.com/index.html#action which is then parsed by my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.