TurboJPEG: Improve error handling
- Provide a new C API function and TJException method that allows calling programs to query the severity of a compression/decompression/ transform error. - Provide a new flag that instructs the library to immediately stop compressing/decompressing/transforming if a warning is encountered. Fixes #151
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
|
||||
* Copyright (C)2017 D. R. Commander. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -46,8 +47,26 @@ public class TJException extends IOException {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TJException(String message, int code) {
|
||||
super(message);
|
||||
if (errorCode >= 0 && errorCode < TJ.NUMERR)
|
||||
errorCode = code;
|
||||
}
|
||||
|
||||
public TJException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a code (one of {@link TJ TJ.ERR_*}) indicating the severity of the
|
||||
* last error.
|
||||
*
|
||||
* @return a code (one of {@link TJ TJ.ERR_*}) indicating the severity of the
|
||||
* last error.
|
||||
*/
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
private int errorCode = TJ.ERR_FATAL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user