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

  • Home
  • SEARCH
  • 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 9124363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:33:19+00:00 2026-06-17T06:33:19+00:00

Im writing a program that should read data from an online XML file. The

  • 0

Im writing a program that should read data from an online XML file. The computation is done by classes written in Scala, should any exception be caught, it must be thrown to a Java class that will handle the exceptions. For some reason, i get an error with the exception type. What is the right exception that should be thrown when trying to access a bad URL or any similar issue (no internet connection?). Thanks!

The main class (Scala)

object test 
{
  def main(args:Array[String])
  {
    val  x:A =  new A()
  }

}

The class that parses the XML file and tries to access the URL

import java.net.{URL, URLConnection}
import xml.{XML, Elem}
import java.lang.NullPointerException
import java.io.IOException


class XMLparser {
  @throws(classOf[Exception])
  private val connectionXMLURL = "http://www.boi.org.il/currency.xml1"
  private var urlConnection:URLConnection = null
  private var url:URL = null
  private var doc:Elem = null
  private val currencies = new java.util.LinkedHashMap[String,java.lang.Double]()

  try
  {
    url = new URL(connectionXMLURL)
    urlConnection = url.openConnection
    doc = XML.load(urlConnection.getInputStream)
  }
  catch
    {
      case ex: org.xml.sax.SAXParseException => //is caught!!! and thrown!
      {
        throw  ex
      }
      case e: IOException =>
      {
        throw e
        //add error log!!
      }

      case e: NullPointerException =>
      {
        throw e
        //add error log!!
      }
      case e: Exception =>
      {
        throw e
      }      
    }

}

The class that should catch the exception (Java)

public class A 
{
    private XMLparser x;
    public A()
    {
        try
        {
            x  = new XMLparser();
        }
        catch(org.xml.sax.SAXParseException e) //Cannot catch it!!??
        {

        }
     /*   catch (Exception e)
        {
             e.printStackTrace();
        } */
    }


}

EDIT: this is the error message i get when trying to catch the exception:

scala: warning: [options] bootstrap class path not set in conjunction with -source 1.6
scala: C:\Users\home\Dropbox\Exchange Currency\src\il\hit\currencyExchange\CurrencyExchangeGUI.java:138: error: exception SAXParseException is never thrown in body of corresponding try statement
scala:       catch (org.xml.sax.SAXParseException ex)
  • 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-17T06:33:20+00:00Added an answer on June 17, 2026 at 6:33 am

    The problem is that you need to declare that your constructor method (the default one) throws a checked java exception. I saw that you already added the @throws(classOf[Exception]) annotation to your code, but it is slightly misplaced for your purposes. Check this link
    https://issues.scala-lang.org/browse/SI-1420

    It should look like

    class XMLparser @throws(classOf[Exception]) {
    
          private val connectionXMLURL = "http://www.boi.org.il/currency.xml1"
          ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program that read string and integers from file, then copy
I'm writing a program to read data from a file, which may be in
Im writing a program that should read input via stdin, so I have the
I'm writing a program that's parsing an XML file to java objects using smooks.
I have this program that reads 2 Kb Data from a binary file adds
I am writing a program that takes in an input file from the user.
I am writing a program in MIPS that will read in signed integers from
I am writing a program that should read in a number of csv files
I am writing a C program that will read and write from/to a serial
I have to write a program that read from a file that contains the

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.