Skip to content

How to get error line and column on the script? if it throw error from custom function? #520

Description

@gellston

Hi chaiscript team.

i just want to know how to get exception error line on the script.

// imported function

std::shared_ptroc::ocImage imread(std::string _path, bool _isColor) {

cv::ImreadModes mode = cv::IMREAD_GRAYSCALE;

if (_isColor)
	mode = cv::IMREAD_COLOR;

cv::Mat cvImage = cv::imread(_path, mode);

if (cvImage.empty()) {
	OCERROR(error)
	OCERRORWRITE(error, "image file not found")
	throw std::runtime_error(error);
}

int depth = 1;
if (cvImage.depth() == CV_8U || cvImage.depth() == CV_8S)
	depth = 1;
else if (cvImage.depth() == CV_16U || cvImage.depth() == CV_16S)
	depth = 2;

std::shared_ptr<oc::ocImage> image = std::shared_ptr<oc::ocImage>(new oc::ocImage(cvImage.cols, cvImage.rows, cvImage.channels(), depth, cvImage.data));

return image;

}

/// Script txt
import("cv");

var image1 = cv.imread("D:\Github\OpenScript\TestScript\Lenna.png",false);
var test2 = cv.imread("D:\Github\OpenScript\TestScript\Lenna.png",true);

as you can see this function i made throw std::runtime_exception contain error information.
(this error info contain error line , ex: LINE , FUNCTION, with using custom macro function OCERROR)

but it not means that this throw contain error line on script like chaiscript::exception::eval_error's start_position.line, start_position.column

if i need to modify chaiscript source code ,,,, could you let me know how to do?

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions