Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-05

fpjson/jsonparser: EJSONScanner vs EScannerError

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luiz Americo Pereira Camara

I found that to handle error while parsing json through TJSONParser is necessary to consider two types of exceptions:

EJSONScanner from jsonparser
EScannerError from jsonscanner

This has the drawback of need to duplicate code like:

    on E: EJSONScanner do
     begin
       ShowMessageFmt('Error parsing "%s" : %s', [FileName, E.Message]);
     end;
     on E: EScannerError do
     begin
       ShowMessageFmt('Error parsing "%s" : %s', [FileName, E.Message]);
     end;

Also requires to add jsonscanner to uses clause

Is it supposed to be this way?
Is there any benefit?
Should a bug report be made?

Luiz

Reply by email

Michael Van Canneyt
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote 21 lines
I found that to handle error while parsing json through TJSONParser is necessary to consider two types of exceptions: EJSONScanner from jsonparser EScannerError from jsonscanner This has the drawback of need to duplicate code like: on E: EJSONScanner do begin ShowMessageFmt('Error parsing "%s" : %s', [FileName, E.Message]); end; on E: EScannerError do begin ShowMessageFmt('Error parsing "%s" : %s', [FileName, E.Message]); end; Also requires to add jsonscanner to uses clause Is it supposed to be this way? Is there any benefit?

Well, there are 2 different kinds of errors: scanner errors, and parser errors. They should have 2 different classes.

Should a bug report be made?

You can submit a request so they are merged (or one made a descendent of the other).

Mochael.

Reply by email

Luiz Americo Pereira Camara
to Michael Van Canneyt
Michael Van Canneyt wrote 13 lines
On Sun, 29 May 2011, Luiz Americo Pereira Camara wrote: > I found that to handle error while parsing json through TJSONParser > is necessary to consider two types of exceptions: > > EJSONScanner from jsonparser > EScannerError from jsonscanner > Well, there are 2 different kinds of errors: scanner errors, and > parser errors. They should have 2 different classes.

OK

EJSONScanner seems misleading since hints to a scanner error

Show quoted text 6 lines
> Should a bug report be made? You can submit a request so they are merged (or one made a descendent of the other).

Done:

http://bugs.freepascal.org/view.php?id=19444

Luiz

Reply by email

Unknown author
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote 18 lines
On 29/5/2011 18:57, Michael Van Canneyt wrote: > > > On Sun, 29 May 2011, Luiz Americo Pereira Camara wrote: > >> I found that to handle error while parsing json through TJSONParser is >> necessary to consider two types of exceptions: >> >> EJSONScanner from jsonparser >> EScannerError from jsonscanner >> Well, there are 2 different kinds of errors: scanner errors, and parser >> errors. > They should have 2 different classes. OK EJSONScanner seems misleading since hints to a scanner error

You are right, it is misleading.

Show quoted text 10 lines
> >> Should a bug report be made? > > You can submit a request so they are merged (or one made a descendent of > the other). > Done: http://bugs.freepascal.org/view.php?id=19444

Fixed. Renamed and made descendent of EParserError (from Classes unit), so you have to test for 1 exception only.

Michael.

Reply by email