What exception to use for incorrect file format?

I parse a file and find out that it contains unsupported elemnet.

You are applying a general case to specificinstance
without knowing any of the details.Indeed I am. However, generally speaking, a method
that throws Exception is less-than-optimal design in
an API. I will try to illustrate my point.
Throwing an Exception does not provide any clues to
the user of your API about what might go wrong in the
method call, while throwing an
UnsupportedElementException certainly does. An
UnsupportedElementException is much more informative
to the user, while a plain Exception is not. A custom
exception in this case is implicitly clear, even
without consulting the Javadocs.Which is all true if I am writing a library. But most people do not write libraries, they write applications. In applications either exceptions are part of the process flow (explicitly caught) or they are not. The vast majority are not part of the process flow.
>
The only time you should create a custom exceptionis
when you believe it will be possible for someone todo
something intelligent with it.Are you always able to tell in advance whether the
user of you API can do something intelligent with an
exception? Can you make the supposition that the user
can never do anything meaningful with the exceptions
you throw? I am not convinced that you can, at least
not in most of the cases.One should never ever design or code solely based on the "hope" that sometime in the future someone "might" need it. Doing that leads to code bloat, code that is hard to understand and worst of all code that is never tested.
So unless there is a known need a special exception should not be created.
>
If I am creating an application that automatically
moves data via a socket and that must move thedata,
then I don't care why the socket failed to connect.I
am simply going to keep retrying until it does
connect. In this case an Exception is perfectly
acceptable.
On the other hand the same application might wantto
resolve the DNS name first and simply give up if it
can't resolve it. But still continue if the
connection timed out. In this case at least one
custom Exception is needed to differentiate between
the two failure paths.Agreed. And to make the API nice and neat, write two
meaningful custom exceptions to differentiate the
failures. :)Nope. Again that is fine for a library. It is not needed for an application. An application has a purpose which is defined by the requirements. Adding stuff when there is neither a current requirement or when there is no expected future requirement is a bad idea.
I have yet to meet a developer who can accurately predict the future. I have however met many who thought there code could be generalized for many possible imaginary cases that they conceived in their mind.
And all that extra code is never tested by QA (because there are no requirements) and causes maintenance problems down the road because it is not part of the documented infrastructure.
also it forces the user of
you API to catch all Exceptions.That is obviously non-sensical. Regardless of the
checked exception being used, you still have tocatch
it.I did not mean that you force the user of your API to
write a try-catch -block, I meant that you force the
user of your API to catch each and every exception
that inherits from java.lang.Exception. Even
RuntimeExceptions; and that can be a problem.
I have no idea what you are trying to express there.
A checked exception must be caught regardless of what type of checked exception it is. The user might break it out but only if the user expects to do something with a specific type of exception.

Similar Messages

  • What does PS use for a file browser now? I am used to using the file browser on CS1

    What does PS use for a file browser now? I am used to using the file browser on CS1

    Newer versions of Photoshop ships with Adobe Bridge for Organizing image files.  However your not required to use it.  You can also use LightRoom or system utilities like Windows File explorer and Mac Finder.  Photoshop itself uses System dialogs to access your file systems files.   When Photoshop display an Open or Save dialog to you in all probability its a Windows or Mac System dialog.  Photoshop versions may also have some internal Photoshop Dialogs programed by Adobe for accessing your systems file systems.

  • Hi which exception is used for incorrect input????

    hi
    the valid input for my program should be like this...
    12 D or 2 D something like this and if the format is not like this.. i wanna throw an
    exception but don't know which one is appropriate one.. i looked up API but there are
    so many....and..can't find one..so..plz help me!!~~! my code is..
    StringTokenizer str = new StringTokenizer(handedCard);
                                    if (str.countTokens() != 2) {
                                      throw //what shoud be here..??                 
                                 }thx guys..here..

    syntax: public class classname or method() throwsI don't think a class can't declare that it throws an exception.
    Back to the question: You have a few choices here.
    1. throw a non-runtime Exception. These must be caught or thrown. This might be what you want, but in the end, you'd just be throwing your exception back to yourself.
    2. RuntimeException: Doesn't need to be caught (but can be caught) advantage is that maybe all you want to do is quit running or tell the user there was an error
    3. Just check the user imput and if it's wrong ask again.

  • What player to use for ODM file

    Hello,
    I am enjoying listing to audio books on my ipod which I get from the local library. However, so of the titles are only available in the OMD format which will not play on the ipod touch. What is the best way to convert a OMD file to a mp3 file so the ipod will accept and play the audio book? My computer would not play the OMD file either. Thank you for your ideas.

    You can't legaly convert them since that are copy protected.
    Download/install the OverDrive Media Console app to play them on the iPod

  • Firefox keeps asking me what program to use to open file types even though I have selected one and checked "do this for all files of this type" going foward

    I am working in Windows and every time I open an attachment, Firefox asks what program to use to open files of this type. I always select the proper program and then check the box that says use this program for all future files of this type. In spite of that, the program continues to ask for every file. How do I turn off this feature and just have the program remember the correct program to use for each type of file extension?

    Regardless of your download preferences, web servers can trigger a download prompt by sending either the ''Content-Type: application/octet-stream'' or the ''Content-Disposition: attachment'' header. You can check if that's the case by examining the server response headers in the [https://developer.mozilla.org/docs/Tools/Web_Console Web Console].
    For the latter problem install the InlineDisposition add-on and see if it helps.
    * https://addons.mozilla.org/firefox/addon/inlinedisposition/
    If the problem persists, post back here with either an example link or a screenshot of the relevant response headers in the Web Console.
    * [[How do I create a screenshot of my problem?]]

  • When opening .doc from website link, FF appends .docx extention to file & does not open in Word 2010, with incorrect file format error. Pls Help

    I'm using Firefox v12 to open a hyperlink from a website that points to a filename.doc MS Word Document for download.
    We are then asked to open the file with MS Word (Default), which our installed version is MS Word 2010.
    Firefox then renames the file appending a .docx to the filename e.g filename.doc.docx. MS Word 2010 opens with error 'incorrect file format', which is correct as Firefox has renamed it.
    Is there a fix or workaround for this?

    Hello Jscher2000,
    I can save the file and it opens fine.
    It's when I open it directly, Firefox appends the 'docx' extenstion to the filename.
    If I continue to reopen from the web link, Firefox renames the file as so
    mydoc.doc-1.docx
    mydoc.doc-2.docx
    mydoc.doc-3.docx
    I can open a .doc from a Microsoft site ok.
    I have the feeling it's the way the web server is reporting the mime type to Firefox.
    The link in question works fine in Internet Explorer.
    best regards,
    Youngielinux.

  • What is NTFS used for?

    What is NTFS used for?
    How does it work?

    It's the standard Windows file system.
    During installation, the Microsoft Windows installer asks me to format the Windows partition using NTFS or FAT. Which should I use?
    If the partition is 32 GB or smaller, you can use either FAT or NTFS. If it's larger than 32 GB, or you are installing Microsoft Vista, then you can only format it using NTFS. Mac OS X can read and write FAT volumes, but only read NTFS volumes. Refer to the Microsoft Windows documentation if you are not sure which best suits your needs.
    http://support.apple.com/kb/HT1656

  • AAC VS  AC3 VS AIFF VS MP3 WHAT IS THE BEST PRO AUDIO FILE FORMAT

    AAC VS  AC3 VS AIFF VS MP3 WHAT IS THE BEST PRO AUDIO FILE FORMAT???
    I detached the audio from my music video and am trying to make a master copy in the highest pro audio format...what would be the best for quality and sound?
    Im using FCPX

    AIFF

  • What font is used for the menu of Illustrator CS5?

    What font is used for the menu of Illustrator CS5?
    I know how to change the default font, which is used to input characters.
    But, I do not know how to check the font used in the menu.
    Is it the font that is described in the following files?
    C:\Users\[UserName]\AppData\Roaming\Adobe\Adobe Illustrator CS5 Settings\ja_JP\AIPrefs
    If you know, please tell me how to check the configuration file and how to change the font that is used in the menu.

    If your using windows xp and applied the 12.02 update, then this is a known bug in
    the update effecting xp users and adobe is working on a fix.
    see this thread
    http://forums.adobe.com/thread/762392?tstart=30
    MTSTUNER

  • Package question - what are the uses for  /var/sadm/pkg ?

    I'm writing packages and noticed once a packages is installed using pkgadd, that files and dirs are created in the /var/sadm/pkg directory. I'm specificly intereseted in the pkginfo file - it contains all the variables from my request script and their values. My question is what are all the uses for this file?
    I've noticed that pkginfo reads from it but would there be any problem deleting certain lines from that file (lines not used by pkginfo - just variables used in the request script that I'd really rather not have floating around in a publicly accessable file).
    thanks!
    Bob

    I'm refering specificly to the file "/var/sadm/pkg/<pkgName>/pkginfo" - it's created during pkgadd and contains all the variable-value pairs from the packages pkginfo file as well as any variables used in the request script and copied to it's temporary response file. I'm not refering to the pkginfo file that you create as a package infofile component.
    I want to remove, from the /var/sadm/pkg/<pkgName>/pkginfo file, certain var-value pairs that were used in my request scripts (not part of the InfoFile/pkginfo component). Otherwise, any user can look at this file or run 'pkgparam <pkgName>' and get that sensative info.
    To the best of my knowledge, this file is only used by the commands pkgparam and pkginfo. Are there other uses?
    My worries are:
    -is it OK to remove lines manually during the postinstall script?
    -will doing this cause problems with any admin or package maintenance functions?
    Thanks-
    Bob

  • What SPAD is used for?

    what SPAD is used for?

    Hi,
    1.look here:
    http://help.sap.com/saphelp_47x200/helpdata/en/7e/36e4c4023411d399b70000e83dd9fc/frameset.htm
    2.Could you please look at the below link, it will explain how to create a new page format
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/4a959551ea11d189570000e829fbbd/content.htm
    Tools --> CCMS --> Spool --> Spool administration. Then choose Full administration and then Page formats on the DeviceTypes tab page
    On next page,choose.. Change, create and fill in the fields, now replace this page format in your script, don't forget to activate it.
    Regards,
    Shiva Kumar

  • What is OEM_sqlplus_input_finished used for?

    During recovery of my database just for testing purpose I got such error:
    Prosz� poda� dziennik: {<RET>=sugerowany | nazwa_pliku | AUTO | CANCEL}
    ORA-00308: you can't open archived log 'OEM_sqlplus_input_finished'
    ORA-27041: can't open file
    OSD-04002: can't open file
    O/S-Error: (OS 2) System can't find file.
    The OEM_sqlplus_input_finished sounds misterious to me. What is it used for?
    Some words you can see above you probably don't understand are in Polish.
    Chris

    ORA-00308 cannot open archived log 'string'
    Cause: The system cannot access a required archived redo log file.
    Action: Check that the offline log exists, the storage device is online, and the archived file is in the correct location. Then attempt to continue recovery or restart the recovery session.
    OEM is a tool for administering Oracle Databases
    OEM = Oracle Enterprise Manager
    That message perhaps was because of those applications
    were getting close.
    You can check, too the alert file of the database.
    Joel P�rez

  • What is FILE_PLP_STATIC_STATUS used for ?

    Does anyone know what FILE_PLP_STATIC_STATUS is used for? It's used as a source in mapping PLP_StatusDimension_LoadStaticValues. It's part of the files that are needed for a Universal Connector run for Supply Chain Management. But there are no details about what should populate it.
    Thanks for the help!
    -Joe

    ORA-00308 cannot open archived log 'string'
    Cause: The system cannot access a required archived redo log file.
    Action: Check that the offline log exists, the storage device is online, and the archived file is in the correct location. Then attempt to continue recovery or restart the recovery session.
    OEM is a tool for administering Oracle Databases
    OEM = Oracle Enterprise Manager
    That message perhaps was because of those applications
    were getting close.
    You can check, too the alert file of the database.
    Joel P�rez

  • Trying to copy a 10gb file to a memory stick but theres an error msg file to large for the file format of the stick. is there a way around this

    trying to copy a 10gb file to a memory stick but there's an error msg, file to large for the file format of the stick. is there a way around this

    If you use 'Disc Utility' you can format the stick (this will erase its contents) to be exFat which will still work with Mac and Windows but allow a larger file sizes to be placed onto the stick.
    Disc Utility > Click the drive on the left > Erase (tab) > Change format to ExFat > Erase > Try putting the file on to the stick again.

  • Unable to save PDF's from Internet Explorer. Error "The document could not be saved. The disk you were saving to or the disk used for temporary files is full. Free some space on this disk and try again, or save to a different disk."

    We are currently in a published desktop environment in Citrix XenApp 6.5.  Server is running on Windows 2008 R2.  Users are not able to save PDF's into the redirected folders (ie Desktop or My Documents).  Exactly same issue described in "The disk you were saving to or the disk used for temporary file is full...."  Anyone has any suggestion??

    Same problem here. Any ideas?
    Saving with Shortcut "CRTL+SHIFT+S" works just fine.
    Using IE 11.0.9600.17728 and Adobe Reader 11.0.10

Maybe you are looking for

  • Use of SAR files in PAR file development

    Can anyone tell me the need for executing the SAR files after the deploying NWDS.

  • Mixed case in column & table name

    Hi, How can tell SQL to use mixed case for column & table name? For example: create table PerNode (netId number, nodeId number); select netId, nodeId from PerNode; The above statements automatically made to upper case. But I wanted to retain the case

  • DBAT Connector Issue

    Hi, I am getting the following error while defining a DBAT connector for Oracle Database. There is only one Table which I am defining for that connector. I do not face the issue while defining the connector for other tables in other oracle database.

  • Safari 5.1.7 stopped working, can't find a new download

    Everytime I attempt to open Safari 5.1.7  I get a message that it quit unexpectly .  If I hit reopen I receive the same message.  I've tried reinstalling the operating system (twice) and that hasn't helped.  I can't find a specific download for versi

  • Changes to HDCP support since ATV 2.2?

    Is there a verdicht on whether Apple has changed HDCP support in the latest release of Apple TV software (2.2). Before this release I could buy and play movies from iTunes as long as it was stated that the movie was available in HD on Apple TV. Since